/**
 * jQuery Slideshow plugin with UI Slider
 *
 * @author:  Dariusz Pobożniak | http://pobozniak.pl
 * @version: 1.0
 */

(function($) {
    $.fn.slideShow = function(options) {
        var defaults = {
            classVisible : 'active',
            slider       : '#slider',
            index        : 0,
            sliderValue  : 3000,
            sliderMin    : 2000,
            sliderMax    : 10000,
            sliderStep   : 1000
        },
        options = $.extend(defaults, options);
        
        var obj = {
            othis : this,
            slideSwitch : function() {
                var $active = $('li.'+options.classVisible, this.othis);
                var $next = ($active.next().length) ? $active.next() : $('li:first-child', this.othis);
                $active.hide().removeClass(options.classVisible);
                $next.fadeIn(1000).addClass(options.classVisible);
            }
        };
        
        return this.each(function() {
            obj.othis = $(this);
            
            $('li:eq('+options.index+')', obj.othis).addClass(options.classVisible);
            $(options.slider).slider({
                value : options.sliderValue,
                min   : options.sliderMin,
                max   : options.sliderMax,
                step  : options.sliderStep,
                slide : function(event, ui) {
                    clearInterval(timer);
                    timer = setInterval(obj.slideSwitch, 12000-ui.value);
                }
            });
        	
            timer = setInterval(obj.slideSwitch, 12000-$(options.slider).slider('value'));
        })
    }
}) (jQuery);