var currentPhoto = 0;
var secondPhoto = 1;
var currentOpacity = new Array();
var FADE_STEP = 2;
var pause = true;

function cfInit(FADE_INTERVAL, FIRST_INTERVAL, PIC_INTERVAL, END_INTERVAL) {
	mHTML="";
	for(i=0;i<imageArray.length;i++)mHTML+="<img id=\"photo"+i+"\" name=\"photo"+i+"\" style=\"FILTER: Alpha(opacity=0);  POSITION: absolute; -moz-opacity: 0\" src=\"images/" + imageArray[i]  +"\">";
	document.getElementById("cfContainer").innerHTML = mHTML;
   
		currentOpacity[0]=99;
		for(i=1;i<imageArray.length;i++)
			currentOpacity[i]=0;
		if(document.all) {
			document.getElementById("photo"+currentPhoto).style.filter="alpha(opacity=100)";
		} else {
			document.getElementById("photo"+currentPhoto).style.MozOpacity = .99;
		}
	
		if(imageArray.length > 1)
			mInterval = setInterval("crossFade("+PIC_INTERVAL+","+END_INTERVAL+")",FADE_INTERVAL);
		xInterval = setTimeout("pause=false",FIRST_INTERVAL);
}

function crossFade(PIC_INTERVAL, END_INTERVAL) {
	if(pause)return;

	currentOpacity[currentPhoto]-=FADE_STEP;
	currentOpacity[secondPhoto] += FADE_STEP;

	if(document.all) {
		document.getElementById("photo"+currentPhoto).style.filter = "alpha(opacity=" + currentOpacity[currentPhoto] + ")";
		document.getElementById("photo"+secondPhoto).style.filter = "alpha(opacity=" + currentOpacity[secondPhoto] + ")";
	} else {
		document.getElementById("photo"+currentPhoto).style.MozOpacity = currentOpacity[currentPhoto]/100;
		document.getElementById("photo"+secondPhoto).style.MozOpacity =currentOpacity[secondPhoto]/100;
	}

	if(currentOpacity[secondPhoto]/100>=.98) {
		currentPhoto = secondPhoto;
		secondPhoto++;
		pause = true;
		if(secondPhoto == imageArray.length) {
			secondPhoto=0;
			xInterval = setTimeout("pause=false",END_INTERVAL);
		} else
			xInterval = setTimeout("pause=false",PIC_INTERVAL);
	}
}

function cfPause()  {
	if(pause) {
		pause = false;
		document.getElementById("pauseBtn").value = "pause";
	} else {
		pause = true;
		document.getElementById("pauseBtn").value = "play";
	}
}
