setInterval works only the first time
<p>I am trying to use <code>setTimer</code> to animate a slide show using straightforward jQuery. I provide the user with a button (in the form of a "DIV" with a button background image) that he clicks to start the show and which then turns into a pause button. The slides are supposed to change every 3 seconds. Here is the relevant code:</p>

<pre><code>    playLink  = $('&lt;div id="lbPlayLink"  /&gt;').click(function(){
            $(playLink).hide();
            $(pauseLink).show();
            slideInterval = setInterval(function(){next()}, 3000)
    })[0];
    pauseLink = $('&lt;div id="lbPauseLink" /&gt;').click(function(){
            $(playLink).show();
            $(pauseLink).hide();
            clearInterval(slideInterval);
    }).hide()[0];
</code></pre>

<p>The next() function call does the work of replacing the slide with the next one. I have checked out this function and it works perfectly if I call it directly (synchronously), however, when it gets called asynchronously by the <code>setInterval</code>, it works fine the first time (3 seconds after I click on the button), but is never called again, even though it should be called 3 seconds later. I know it's never called as I put an "alert" call at the beginning and end of the function.</p>

<p>If I replace the <code>next()</code> call in the <code>setInterval</code> with <code>alert('test')</code> then I can see the <code>setInterval</code> is doing what it is supposed to. I can't for the life of me see why <code>alert()</code> is OK but <code>next()</code> isn't, unless it has something to do with "scope" of functions, but in that case why does it work the first time?</p>

<p>I've tried debugging the code with firebug, but it can't really help with timeout functions like this. Neither Firefox nor IE8 show any error messages.</p>

<p>I've looked through the various posts here and elsewhere on <code>setInterval</code>, but can't see anything relevant that I haven't tried already. I've been experimenting now for about 3 hours and it's doing my head in. Can anyone suggest what I can try next?</p>
