(function($) {
    
    $.fn.slideShow = function(opts) {
        
        if (opts) {$.extend(conf, opts);}
        
        var showcaseItems = $('li','#images', this);                
            currentIndex = 0,
            showcaseItemsLength = showcaseItems.length,
            nav = '',
            obj = this;
        
        //add pagination
        for(i=0; i<showcaseItemsLength; i++) {
            nav += '<li><a href="#">item' + i + '</a></li>\n';
        }        
        $(this).prepend('<ul id="slide-nav">' + nav + '</ul>');
        
        //set opacity
	if(!($('html').hasClass('lt-ie9'))){
	    $('p', '#intro', this).fadeTo(0, .75);
	}
        $('#to_work', '#intro', this).hover(
            function() {
                $(this).fadeTo(0, .75);        
            },
            function() {
                $(this).fadeTo(0, 1);
            }
        );
            
        var triggerTimer = function() {
            if((currentIndex + 1) >= showcaseItemsLength) currentIndex = -1;            
            $('a', '#slide-nav').eq(currentIndex + 1).click();
        };
        
        var timer = setInterval(triggerTimer, 6000);    
       
        $('a', '#slide-nav').click(function() {
            
            clearTimeout(timer);
            timer = setInterval(triggerTimer, 6000);
            
            $('a', '#slide-nav').eq(currentIndex).removeClass('active');
            
            currentIndex = $(this).parent().index();            
            $(this).addClass('active');
           
            var showcaseItem = showcaseItems.eq(currentIndex);
                color = showcaseItem.data('color');
                
            $('#intro', obj).stop(true, true).animate({backgroundColor: color});   
            
            showcaseItems.stop(true, true).hide();
            showcaseItem.stop(true, true).fadeIn();
        }).first().click();
    };
    
})(this.jQuery);
