jQuery - scroll down every x seconds, then scroll to the top
<p>I have a scrollable div that I want to scroll down 50 pixels every X seconds.  That's fine and working.</p>

<p>I also have a seperate function that scrolls the div back to the top when it reaches the bottom.  Also fine; working.</p>

<p>Now, I need to combine the two so the scrolldown is ignored until we have scrolled to the top again.  </p>

<p>I have a 'working' example here, as you'll see it has some pretty nutty behavior: <a href="http://jsfiddle.net/JVftf/" rel="nofollow">http://jsfiddle.net/JVftf/</a></p>

<pre><code>window.setInterval(scrollit, 3000);

function scrollit() {
    $('#scroller').delay(2000).animate({ scrollTop: $("#scroller").scrollTop() + 50 }, 'slow');
}

$('#scroller').bind('scroll', function () {
    if ($(this).scrollTop() + $(this).innerHeight() &gt;= $(this)[0].scrollHeight) {
        $('#scroller').delay(2000).animate({ scrollTop: 0 }, 1000);
    }
});
</code></pre>
