(function ($) {
    
    jQuery.fn.cycle.updateActivePagerLink = function (pager, current) {
        
        jQuery(pager).find('a').removeClass('active').filter(':eq(' + current + ')').addClass('active');
        
    };

    jQuery.fn.cycle.transitions.scrollHorzFade = function ($container, $slides, options) {
        
        $container.css('overflow', 'hidden');
        
        options.before.push(function ($current, $next, options, forward) {
            
            jQuery(this).show();
            
            options.cssBefore = {left: (forward) ? $next.offsetWidth : -$next.offsetWidth, opacity: 0};
            options.animIn = {left: 0, opacity: 1};
            options.animOut = {opacity: 0, left: (forward) ? -$current.offsetWidth : $current.offsetWidth};
            
            $slides.not($current).css(options.cssBefore);
            
        });
        
        options.cssFirst = {left: 0};
        options.cssAfter = {display: 'none'};
        
    };
    
    jQuery.fn.slideshow = function (options) {
        
        if (!options) {
        	options = {};
        }
        options = jQuery.extend({}, jQuery.fn.slideshow.defaults, options);
        
        return this.each(function () {
            
            var $slideshow = $(this);
            var $slides =  $slideshow.find('div.slides');
            var $prev = $slideshow.find('div.prev');
            var $next = $slideshow.find('div.next');
            var $pager = $slideshow.find('div.pager');
            var $navigation = $prev.add($next).add($pager);
            
            var settings = options;
            settings.prev = $prev;
            settings.next = $next;
            settings.pager = $pager;
            
            $slides
                .cycle(settings)
                .bind('mouseenter', function () {
                    
                    $(this).cycle('pause'); 
                    
                })
                .bind('mouseleave', function () {
                    
                    $(this).cycle('resume');
                    
                });
            
            $prev
                .bind('mouseenter', function () {
                
                    $(this).addClass('active');
                    
                })
                .bind('mouseleave', function () {
                
                    $(this).removeClass('active');
                    
                });
            
            $next
                .bind('mouseenter', function () {
                
                    $(this).addClass('active');
                    
                })
                .bind('mouseleave', function () {
                
                    $(this).removeClass('active');
                    
                });
            
        });
        
    };
    /*  */
    jQuery.fn.slideshow.defaults = {
        fx: 'scrollHorzFade',  
        speed: 700,
        easing: 'easeInOutQuad',
        timeout: 5000
    };
    
    jQuery(function ($) {
        
        $(this).pngFix();
        
    });
    
})(jQuery);
