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

var d = document, current = 0, nIndex = 0, imgs = new Array(), zInterval = null, pause = false, count = 0;

function init() {
	if(!d.getElementById || !d.createElement){
		return;
	}
	if(d.getElementById("presentation") != null) {
		imgs = d.getElementById("presentation").getElementsByTagName("div");
		for(i = 0; i < imgs.length; i++) {
			imgs[i].xOpacity = 0;
			count = count + 1; 	
		}
		if(count > 0) {
			current = Math.round(Math.random() * (count - 1));
			nIndex = current;
			while (current == nIndex) {
				nIndex = Math.round(Math.random() * (count - 1));	
			}
			imgs[current].style.display = "block";
			imgs[current].xOpacity = .99;
			setTimeout(fade, 10000);	
		}
	}
}

function fade() {
	cOpacity = imgs[current].xOpacity;
	nOpacity = imgs[nIndex].xOpacity;	
	cOpacity -= .05; 
	nOpacity += .05;	
	imgs[nIndex].style.display = "block";
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;	
	setOpacity(imgs[current]); 
	setOpacity(imgs[nIndex]);	
	if(cOpacity <= 0) {
		imgs[current].style.display = "none";
		current = nIndex;
		while (current == nIndex) {
			nIndex = Math.round(Math.random() * (count - 1));	
		}
		setTimeout(fade, 10000);
	} else {
		setTimeout(fade, 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) + ")";
	}	
}
