stop animations in functions

stop animations in functions

Hi

I have images that fade in an out in the background. I've put them in functions.
When clicking on a button I want them all to fade and stop running.
I find no way of doing this.
I have tried using stop(), clearQueue() and finish() in different ways but nothing works? 

This is my code:

  1. function aniBG2() {
  2.       bg2.delay(4000).animate({ opacity: 1,
  3.       }, 10000, function() {

  4.             bg3.animate({ opacity: 1,
  5.             }, 10000, function() {

  6.                   bg3.delay(5000).animate({ opacity: 0,
  7.       }, 10000, function() {

  8.             bg2.animate({ opacity: 0,
  9.                   }, 10000, function() {
  10.                         aniBG2();
  11.                   });
  12.             });
  13.          });
  14.   });
  15. }
  16. function aniBG4() {
  17.       bg4.delay(7000).animate({ opacity: 1,
  18.       }, 10000, function() {

  19.             bg4.delay(4000).animate({ opacity: 0,
  20.              }, 10000, function() {
  21.                   aniBG4();
  22.             });
  23.       });
  24. }
  25. function aniBG5() {
  26. bg5.delay(2000).animate({
  27.     opacity: 1,
  28. }, 10000, function() {

  29. bg5.delay(6000).animate({
  30.     opacity: 0,
  31. }, 10000, function() {
  32. aniBG5();
  33.   });
  34.   });
  35. }



  36. $('#logo').on('click', function(e){
  37. bg2.stop(true,true).animate({opacity: 0}, function() {
  38.             bg2.clearQueue().finish();
  39.       });
  40. bg3.stop(true,true).animate({opacity: 0}, function() {
  41.             bg3.clearQueue().finish();
  42.       });
  43. bg4.stop(true,true).animate({opacity: 0}, function() {
  44.             bg4.clearQueue().finish();
  45.       });
  46. bg5.stop(true,true).animate({opacity: 0}, function() {
  47.             bg5.clearQueue().finish();
  48.       });
  49. });
Grateful for help.