
// thanks to http://jonraasch.com/blog/a-simple-jquery-slideshow

(function($) {
	$.fn.shuffle = function(options){
			var opts = $.extend({}, $.fn.shuffle.defaults, options);
			opts.wrapper = this;
			opts.first_run = true;

			// add extra images			
			$(opts.images).each(function() {
				opts.wrapper.append("<img src='" + opts.prefix + this + "' style='display: none;' />");
			});
			// start it quick, run it slower
			window.setTimeout(function() {
				$.fn.shuffle.go(opts);
	    }, opts.time_to_start);
	
	};
	
	$.fn.shuffle.go = function(opts) {
			$('IMG',opts.wrapper).show();
	    var $active = $('IMG.active',opts.wrapper);
	    var $next =  $active.next().length ? $active.next() : $('IMG:first',opts.wrapper); // $('#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');
	        });
			if(opts.first_run) {
				opts.first_run = false;
				opts.wrapper.cycleTimeout = setInterval(function(){$.fn.shuffle.go(opts)}, opts.timeout);
			}
	}
	
	$.fn.shuffle.defaults = {
		auto	: 1,
		easing	: null,
		prefix	: '/images/home/',
		images: new Array(
				// 'A.jpg',
				'B.jpg',
				'C.jpg'
			),
		transition	: 800,
		time_to_start	: 1500,
		timeout : 3000  // ms per image
	};

})(jQuery);
