/* God bless Jon Raasch (jonraasch.com) */

/* // ORIGINAL

function slideSwitch(slideshow) {
	$('.slideshow').each(function(elem){
		var $active = $(this).find('img.active');
		if ( $active.length == 0 ) $active = $(this).find('img:last');
		var $next =  $active.next().length ? $active.next(): $(this).find('img:first');
		$active.addClass('last-active');
		$next.css({opacity: 0.0})
			.addClass('active')
			.animate({opacity: 1.0}, 1000, function() {
				$active.removeClass('active last-active');
			});
	});
}

$(function() {
	$('.slideshow').find('img:first').addClass('active');
	$('.slideshow').parent('li').addClass('clearfix');
	setInterval("slideSwitch();", 3000 );
});

*/

function rand(min,max) { return Math.floor((Math.random() * (max-min+1))+min); }

function slideSwitch(i) {
	var elem = $('.slideshow')[i];
	var $active = $(elem).find('img.active');
	if ( $active.length == 0 ) $active = $(elem).find('img:last');
	var $next =  $active.next().length ? $active.next(): $(elem).find('img:first');
	$active.addClass('last-active');
	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 1000, function() {
			$active.removeClass('active last-active');
		});
}

$(function() {
	$('.slideshow').find('img:first').addClass('active');
	$('.slideshow').parent('li').addClass('clearfix');
	$('.slideshow').each(function(i){
		var randy = rand(0,1000);
		$('html').animate({'left':0}, randy, 'linear', function() {setInterval("slideSwitch("+i+");", 3000-randy )});
	});
	
});