title: Looping Function (Javascript Callback Help)
body: <p>I haven't done much with Javascript functions and am trying to get a function to loop itself after a short delay. I've seem some code using setTimeout() but I can't seem to figure out how to get it to work in my instance, here's my code:</p>
  
  <pre><code>var number = 8;
  var iter = 1;
  
  function slide_function(iter, amount, callback){    
      if(iter&lt;amount){
          console.log('test');
  
          $('#tagline_slideshow span#' + iter).delay(delayTime).fadeOut(1600, function(){         
              $(this).next('span').fadeIn();      
          });
  
          var iter = iter + 1;
      }
      else if(iter==amount){
          console.log('test2');
  
          var iter = 1;
  
          $('#tagline_slideshow span#' + iter).delay(delayTime).fadeOut(1600, function(){         
              $(this).next('span').fadeIn();      
          });
  
          var iter = iter + 1;
      }
  }
  
  slide_function(iter, number, setTimeout(slide_function(iter, number),5000));
  </code></pre>
  
  <p>I'm trying to basically create a little slideshow type thing where elements fade in and out up to a certain point and then start over again. It works the first time through the function but then doesn't run it again. I did make some mistakes where it caused an infinite loop where it pretty much crashed my browser so I'm treading lightly at this point.</p>
  
  <p>I'm assuming the issue lies in my callback function? I'm trying to do a 5000 ms delay before the function runs again.</p>
  
  <p>Any help would be greatly appreciated. Thanks!</p>