window.addEventListener?window.addEventListener("load",init,false):window.attachEvent("onload",init);

/* performance variables */
var pause=true; //pause between fades, true or false
var fadeDuration = 1; //duration of the cross-fades in seconds
var pauseDuration = 3 //duration of the pause between frames in seconds

var frames = new Array();
var current=0;

function init() {
	frames = document.getElementById("slideshow").getElementsByTagName("img");
	for(i=1;i<frames.length;i++) frames[i].xOpacity = 0;
	frames[0].style.display = "block";
	frames[0].xOpacity = .99;

	if (pause==true) {
		timer = setTimeout('endpause()',(pauseDuration*1000));
		}

	else {
		setTimeout(crossfade,(fadeDuration*1000));		
		}
}

function crossfade() {
	cOpacity = frames[current].xOpacity;
	nIndex = frames[current+1]?current+1:0;

	nOpacity = frames[nIndex].xOpacity;
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	frames[nIndex].style.display = "block";
	frames[current].xOpacity = cOpacity;
	frames[nIndex].xOpacity = nOpacity;
	
	setOpacity(frames[current]); 
	setOpacity(frames[nIndex]);
	
	if(cOpacity<=0) {
		frames[current].style.display = "none";

		if (pause==true) {
			timer = setTimeout('endpause()',(pauseDuration*1000));
			}

		else {
			setTimeout(crossfade,(fadeDuration*1000));		
			}

		current = nIndex;

	} else {
		setTimeout(crossfade,50);
	}
	
	function setOpacity(obj) {
		if(obj.xOpacity>.99) {
			obj.xOpacity = .99;
			return;
		}
		obj.style.opacity = obj.xOpacity;
		obj.style.MozOpacity = obj.xOpacity;
		obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
	}
	
}

function endpause() {
	setTimeout(crossfade,(fadeDuration*1000));
	return false;
}