var imageMax;
var imageCount;
var path;
var currentImage;
var ieFix; //IE fix for opacity
var browser = navigator.appName;

function init() {
	/*number of images in the images folder. images must be numbered file name,
	  e.g., 1.png, 2.png, etc. Never name any files "0.png".
	  files must be in ".png" format.*/
	imageMax = 6;
	imageCount = 0;
	
	//get path of file on server to enable changing the .src
	path = document.getElementById("image1").src;
	//truncate the file name off the path, i.e., "1.png"
	path = path.substring(0, path.length - 5);
	ieFix = document.getElementById("image1").style.filter = "alpha(opacity = 0)";
	
	switchImage();
} //end init()

function switchImage() {
	imageCount++;
	if (imageCount == 1) {
		currentImage = document.getElementById("image" + parseInt(imageCount));
		fadeIn();
	} else if (imageCount <= imageMax) {
		currentImage.src = path + parseInt(imageCount) + ".png";
		currentImage.id = "image" + parseInt(imageCount);
		currentImage = document.getElementById("image" + parseInt(imageCount));
		fadeIn();
	}	else {
		imageCount = 0;
		currentImage.src = path + parseInt(imageCount + 1) + ".png";
		currentImage.id = "image" + parseInt(imageCount + 1);
		switchImage();
	} //end if
} //end switchImage()

function fadeIn() {
	if (currentImage.style.opacity < 5) { //adjust speed of fade here
		currentImage.style.opacity = Number(currentImage.style.opacity) + .2;
		
		//test browser
		if (browser == "Microsoft Internet Explorer") {
			ieFix = currentImage.style.filter.substring(15, currentImage.style.filter.length - 1);
			currentImage.style.filter = "alpha(opacity = " + (Number(ieFix) + 20) + ")";
		} //end browser test
		
		setTimeout(fadeIn, 100);
	} else {
		fadeOut();
	} //end if
} //end fadeIn()


function fadeOut() {
	if (currentImage.style.opacity > 0) {
		currentImage.style.opacity = Number(currentImage.style.opacity) - .2;
		
		//test browser
		if (browser == "Microsoft Internet Explorer") {
			ieFix = currentImage.style.filter.substring(15, currentImage.style.filter.length - 1);
			currentImage.style.filter = "alpha(opacity = " + (Number(ieFix) - 20) + ")";
		} //end browser test
		
		setTimeout(fadeOut, 100);
	} else {
		switchImage();
	} //end if
} //end fadeOut()













