var imageArray = new Array(
	"img/photo1.jpg","img/photo2.jpg","img/photo3.jpg",
	"img/photo4.jpg","img/photo5.jpg");
var currentPhoto = 0;
var secondPhoto = 1;
var FADE_STEP = 2;
var FADE_INTERVAL = 50;
var pause = false;
var currentOpacity = new Array();

window.onload = function() {
	initSlideshow();
}

function initSlideshow() {
	currentOpacity[0]=99;
	for(i=1;i<imageArray.length;i++) currentOpacity[i]=0;
	mHTML="";
	for(i=1;i<imageArray.length;i++) {
		mHTML += "<div id=\"SlideshowPhoto"+i+"\" class=\"photo\"><img src=\"" + imageArray[i]  +"\" alt=\"\" /></div>";
	}
	document.getElementById("photo").innerHTML += mHTML;
	setOpacity(document.getElementById("SlideshowPhoto"+currentPhoto),100);
	setTimeout("startSlideshow()",5000);
}

function startSlideshow() {
	mInterval = setInterval("crossFade()",FADE_INTERVAL);
}

function crossFade() {
	if(pause)return;
	currentOpacity[currentPhoto]-=FADE_STEP;
	currentOpacity[secondPhoto] += FADE_STEP;
	setOpacity(document.getElementById("SlideshowPhoto"+currentPhoto),currentOpacity[currentPhoto]);
	setOpacity(document.getElementById("SlideshowPhoto"+secondPhoto),currentOpacity[secondPhoto]);

	if(currentOpacity[secondPhoto]/100>=.98) {
		currentPhoto = secondPhoto;
		secondPhoto++;
		if(secondPhoto == imageArray.length) secondPhoto=0;
		pause = true;
		xInterval = setTimeout("pause=false",5000);
	}
}

function setOpacity(obj, opacity) {
	opacity = (opacity == 100) ? 99.999 : opacity;
	obj.style.filter = "alpha(opacity:"+opacity+")";  // IE/Win
	obj.style.KHTMLOpacity = opacity/100;// Safari<1.2, Konqueror
	obj.style.MozOpacity = opacity/100;// Older Mozilla and Firefox
	obj.style.opacity = opacity/100;// Safari 1.2, newer Firefox and Mozilla, CSS3
}
