jQuery animated slideshow within a slideshow plugin. Last slide won't go back to first
<p>I had a guy created a jquery plugin for me. Basically, it was 5 different slideshows within a slidshow. It works fine, except for one thing. Once the last slide finishes, it just stops. I need it to go back to the first slide. Can someone take a look at his code and see if they can help figure it out? Thanks.</p>

<pre><code>&lt;div id="slides"&gt;
                    &lt;div class="slider" id="category0"&gt; 
                        &lt;a class="button prev" href="#" rel="nofollow"&gt;&lt;img src="images/slidePrev.png"/&gt;&lt;/a&gt; 
                        &lt;a class="button next" href="#" rel="nofollow"&gt;&lt;img src="images/slideNext.png"/&gt;&lt;/a&gt; 
                        &lt;div class="holder_cont"&gt; 
                            &lt;ul class="holder"&gt; 
                              &lt;li class="slide first"&gt;
                              &lt;/li&gt; 
                              &lt;li class="slide"&gt; 
                              &lt;/li&gt; 
                              &lt;li class="slide"&gt; 
                              &lt;/li&gt; 
                              &lt;li class="slide"&gt; 
                              &lt;/li&gt;                         
                            &lt;/ul&gt; 
                        &lt;/div&gt; 
                        &lt;div class="clear"&gt;&lt;/div&gt;                            
                   &lt;/div&gt; 

&lt;script&gt;
 ;(function($) {
$.preloadImages = function(images, func) {        
    var i = 0;
    var cache = [];
    var loaded = 0;
    var num = images.length;

    for ( ; i &lt; num; i++ ) (function(i) {
        var new_image = $('&lt;img/&gt;').attr('src', images[i]).load(function(){
            loaded++;

            if(loaded == num)
            {                                                
                func();                   
            }
        });                     
        cache.push(new_image);
    })(i);

    return true;
};

$.fn.imgSlider = function(images) {        
    if (!$(this).length || $(this).length&gt;1) {            
        return this;
    }

    var direction = 'right';
    var e = this;
    var timeout_id = 0;
    var in_progress = false
    var i = 0;
    var num_slides = $(e).find('.holder &gt; li').length;
    var slide_widths = $(e).find('.holder &gt; li:first').width();
    var speed = 900;
    var current=0;

    for ( ; i &lt; num_slides; i++ ) (function(i) {            
        $(e).find('.holder &gt; li').eq(i).css('background', 'url('+images[i]+') no-repeat');
    })(i);

    function slider_animate(to)
    {
        clearTimeout(timeout_id);
        timeout_id = setTimeout(auto_animate, 5000);
        in_progress = true;            

        var toMove = $(e).find('.holder');
        current = to;

        $(toMove).animate({'margin-left':'-'+(slide_widths*to)+'px'}, speed, null, function(){                
            in_progress = false;
        });          
    }

    $(e).find('.holder &gt; li').hover(function(){
        clearTimeout(timeout_id);            
        $(this).find('.caption').stop().fadeTo(500, 0.8);            
    },function(){
        $(this).find('.caption').stop().fadeTo(500, 0);            
        timeout_id = setTimeout(auto_animate, 3500);            
    });

    function auto_animate()
    {

        if (current === num_slides-1) {
            var foo = $('.slider:not(.hidden)').attr('id');
            if ( $(e).attr('id') === foo) {
                if ($('#category'+(parseInt(foo.slice(8))+1)).length) {
                    window.startSlider( parseInt(foo.slice(8))+1 );
                }
            }
        }

        if(direction == 'right')
        {
            var to = current+1;
            if(to&lt;num_slides)
            {

                slider_animate(to);
            }
        }
        else
        {
            var to = current-1;
            if(to&gt;=0)
            {
                slider_animate(to);
            }
            else
            {
                var foo = $('.slider:not(.hidden)').attr('id');
                if ( $(e).attr('id') === foo) {
                    if ($('#category'+parseInt(foo.slice(8))+1).length) {
                        window.startSlider( parseInt(foo.slice(8))+1 );
                    }
                }
            }
        }
    }

    $(e).find('.next').live('click', function(){
        if(!in_progress)
        {
            var to = current+1;

            if (current === num_slides-1) {

                var foo = $('.slider:not(.hidden)').attr('id');
                if ( $(e).attr('id') === foo) {
                    var bar = '#category' + (parseInt(foo.slice(8))+1);
                    if ($(bar).length) {
                        window.startSlider( parseInt(foo.slice(8))+1 );
                    }
                }
            }
            if(to&lt;num_slides)
            {
                slider_animate(to);
            }
            else
            {
                slider_animate(0);
            }
        }

        return false;
    });

    $(e).find('.prev').live('click', function(){
        if(!in_progress)
        {
            var to = current-1;

            if (current === num_slides-1) {
                var foo = $('.slider:not(.hidden)').attr('id');
                if ( $(e).attr('id') === foo) {
                    if ($('#category'+parseInt(foo.slice(8))+1).length) {
                        window.startSlider( parseInt(foo.slice(8))+1 );
                    }
                }
            }

            if(to&gt;=0)
            {
                slider_animate(to);
            }
            else
            {
                slider_animate(num_slides-1);

            }
        }

        return false;
    });

    timeout_id = setTimeout(auto_animate, 3000);

    return true;
};
})(jQuery);
&lt;/script&gt;
</code></pre>
