

// change these paths for your images
var myImages = ['/splash/1.jpg','/splash/2.jpg','/splash/3.jpg','/splash/4.jpg','/splash/5.jpg','/splash/6.jpg','/splash/7.jpg','/splash/8.jpg','/splash/9.jpg','/splash/10.jpg','/splash/11.jpg','/splash/12.jpg','/splash/13.jpg','/splash/14.jpg','/splash/15.jpg','/splash/16.jpg','/splash/17.jpg','/splash/18.jpg','/splash/19.jpg','/splash/20.jpg','/splash/21.jpg','/splash/22.jpg','/splash/23.jpg','/splash/24.jpg','/splash/25.jpg','/splash/26.jpg','/splash/27.jpg','/splash/28.jpg','/splash/29.jpg','/splash/30.jpg','/splash/31.jpg','/splash/32.jpg','/splash/33.jpg','/splash/34.jpg','/splash/35.jpg','/splash/36.jpg','/splash/37.jpg','/splash/38.jpg','/splash/39.jpg','/splash/40.jpg','/splash/41.jpg','/splash/42.jpg','/splash/43.jpg','/splash/44.jpg','/splash/45.jpg','/splash/46.jpg','/splash/47.jpg','/splash/48.jpg','/splash/49.jpg','/splash/50.jpg','/splash/51.jpg','/splash/52.jpg','/splash/53.jpg','/splash/54.jpg'];

// how many times should the photo change per page load
var maxChanges = myImages.length * 2;

// shuffle images so each time page loads, the photos show in different order
var do_shuffle = true;

// use simple randomness instead of shuffling (tends to repeat images too often)
var do_randomly = false;

// number of seconds between photo changes
var seconds_between_photos = 5;

// name of DIV to load photos into
var div_name = "splashImage";








var changes = 0;
var timer;
var thisImg = myImages.length - 1;

//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/array/shuffle [v1.0]

shuffle = function(o){ //v1.0
	for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
	return o;
};




// shuffling is better than random because of less potential repetition
if (do_shuffle) {
	myImages = shuffle(myImages);	
}



function nextImage () {
	
	var low = 0;
	var high = myImages.length - 1;
	var rand_no = Math.floor((high-(low - 1))*Math.random()) + low;
	
	thisImg++;
	changes++;
	if (thisImg==myImages.length) {
		thisImg = 0;
	}
	if (changes==maxChanges) {
		clearInterval(timer);
	}
	if (do_randomly) {
		thisImg = rand_no;
		return myImages[rand_no];
	} else {
		return myImages[thisImg];
	}
}

function changeImage () {
	
	var t = myImages[thisImg];
	var n = nextImage();
	
	if (t != n) {
		$("#"+div_name).addClass("loading");
		showImage(n);
	} else { 
		changeImage();
	}
}

function showImage(src)
{
	$("#"+div_name+" img").fadeOut("slow").remove();
	var largeImage = new Image();
	$(largeImage).load(function()
                        {
							$(this).hide();
                        	$("#"+div_name).append(this).removeClass("loading");
                                             
                       		$(this).fadeIn("slow");              
                        });    
	$(largeImage).attr("src", src);
}

function checkForLoaded () {
	if (document.getElementById(div_name) != null) {
		//alert("loaded");
		clearInterval(timer);
		changeImage();
		timer = setInterval(changeImage, (seconds_between_photos * 1000));
	}
}

// check every second to see if DIV exists, when it does, start photo changing timer
timer = setInterval(checkForLoaded, 500); 



