var nextImage = null;

var nextText = null;



//When the page is loaded, start the image rotator.

$(document).ready(StartImageRotator());



//Set the interval for the image rotator and start.

function StartImageRotator(){

	//Pre-load images

	var img = new Image();

	img.src = "images/homepic1.jpg";

	img.src = "images/homepic1text.jpg";

	img.src = "images/homepic2.jpg";

	img.src = "images/homepic2text.jpg";

	img.src = "images/homepic3.jpg";

	img.src = "images/homepic3text.jpg";

	

	var interval = self.setInterval(RotateImage, 2*1000)

}



//Rotate to the next image.

function RotateImage(){

	//alert("switching");

	switch($("#slideshowPicture").attr("name")){

		

		case "homePic1":

			//alert("Switching to image 2.");

			$("#slideshowPicture").attr("name","homePic2");

			nextImage = "images/homepic2.jpg";

			nextText = "images/homepic2text.jpg";

			break;

		case "homePic2":

			//alert("Switching to image 3.");

			$("#slideshowPicture").attr("name","homePic3");

			nextImage = "images/homepic3.jpg";

			nextText = "images/homepic3text.jpg";

			break;

		case "homePic3":

			//alert("Switching to image 1.");

			$("#slideshowPicture").attr("name","homePic1");

			nextImage = "images/homepic1.jpg";

			nextText = "images/homepic1text.jpg";

			break;

		default:

			alert("ERROR - Cannot rotate Image");

			break;

	}



	DoFadeOut();

}



function DoFadeOut(){

	$("#slideshowPicture").fadeOut("slow", DoFadeIn);

	$("#slideshowText").fadeOut("slow");

	

}



function DoFadeIn(){

	$("#slideshowPicture").fadeIn("slow");

	$("#slideshowText").fadeIn("slow");

	$("#slideshowPicture").attr("src", nextImage);

	$("#slideshowText").attr("src", nextText);

		

}
