// =======================================
// set the following variables
// =======================================

// Set slideShowSpeed and fade speed (milliseconds)
var slideShowSpeed = 4000
var fadeSpeed = 2000;

// Specify the image files
var Pic = new Array() // don't touch this
// to add more images, just continue
// the pattern, adding to the array below
// define random images and owners for display

Pic[0] = '/animation/animation-image-1.jpg';
Pic[1] = '/animation/animation-image-2.jpg';
Pic[2] = '/animation/animation-image-3.jpg';
Pic[3] = '/animation/animation-image-3.jpg';



// =======================================
// do not edit anything below this line
// =======================================

// Image cache to reduce network usage
var FadeCache = new Array();

var fadeIndex = 0;
var fadeDiv = null;

function initSlideShow() {
	fadeDiv = $(".fade").clone();
	fadeDiv.removeClass("fade");

	$(".fade").append(fadeDiv);
	
	rotateImages();
}

function rotateImages() {
	if (++fadeIndex == Pic.length) fadeIndex = 0;
	
	if (FadeCache[fadeIndex] == null) {
		FadeCache[fadeIndex] = new Image();
		$(FadeCache[fadeIndex]).attr("src", Pic[fadeIndex]).load(initFade());
		
	} else {
		initFade();
	}
}

function initFade() {
	if (fadeIndex % 2 > 0)
		$("img", fadeDiv).attr("src", FadeCache[fadeIndex].src);
	else
		$("img:eq(0)", ".fade").attr("src", FadeCache[fadeIndex].src);
	
	setTimeout("doFade()", slideShowSpeed);
}

function doFade(direction) {
	if (fadeIndex % 2 > 0)
		fadeDiv.fadeIn(fadeSpeed, function() { rotateImages(); });
	else
		fadeDiv.fadeOut(fadeSpeed, function() { rotateImages(); });
}


