
(function($) {

    $.fn.listrotator = function(options) {

        var settings = jQuery.extend({
            speed: 2500
        }, options);

        return this.each(function() {
            var $this = $(this);

            $this.find('li').hide();
            $this.find('li').slice(0, 1).show();
            setTimeout(function() { switchImage($this, 0, settings.speed) }, settings.speed);

        });

    };

    switchImage = function($this, current, speed) {
        $this.find('li').slice(current, current + 1).fadeToggle(speed / 2);
        current += 1;
        if (current >= $this.find('li').length)
            current = 0;
        $this.find('li').slice(current, current + 1).fadeToggle(speed / 2, null, function() { switchImageEnd($this, current, speed) });
    };

    switchImageEnd = function($this, current, speed) {
        setTimeout(function() { switchImage($this, current, speed) }, speed);
    };
})(jQuery);

