(function($) {

	$.rotate_fade = {
		defaults: {
			rotation_speed: 5000
		}		
	}

    $.fn.extend({
        rotate_fade: function(config) {
			
			var config = $.extend({}, $.rotate_fade.defaults, config);
			
            return this.each(function() {
	
	            // apply active class to first quote unless already applied elsewhere
                if (! ($(this).find('img.active')).length ) {
                    $('img:first', $(this)).addClass('active');
                };
    
                
                // rotate images with fade effect
                setInterval(function(){
					var $active = $('.slideshow img.active');

				    if ( $active.length == 0 ) $active = $('.slideshow img:last');

				    var $next =  $active.next().length ? $active.next()
				        : $('.slideshow img:first');

				    $active.addClass('last-active');

				    $next.css({opacity: 0.0})
				        .addClass('active')
				        .animate({opacity: 1.0}, 1000, function() {
				            $active.removeClass('active last-active');
				        });
                }, config.rotation_speed);  
                                
            })
        }
    })

})(jQuery);
