/*****

Image Cross Fade Redux
Version 1.0
Last revision: 02.15.2006
steve@slayeroffice.com

Please leave this notice intact. 

Rewrite of old code found here: http://slayeroffice.com/code/imageCrossFade/index.html


*****/


//window.addEventListener?window.addEventListener("load",so_init,false):window.attachEvent("onload",so_init);

var imgs = new Array(), zInterval = 6000, current = 0, pause = false;

function OdahImgFade_init() {
    if (!document.getElementById || !document.createElement) return;

	// DON'T FORGET TO GRAB THIS FILE AND PLACE IT ON YOUR SERVER IN THE SAME DIRECTORY AS THE JAVASCRIPT!
	// http://slayeroffice.com/code/imageCrossFade/xfade2.css
    if (document.getElementById("imageContainer")) {
        imgs = document.getElementById("imageContainer").getElementsByTagName("img");
        if (imgs.length > 0) {
            for (i = 1; i < imgs.length; i++) imgs[i].setAttribute("xOpacity", "0");
            imgs[0].style.display = "block";
            imgs[0].setAttribute("xOpacity", "0.99");
            setTimeout(OdahImgFade_xfade, zInterval);
        }
    }
}

function OdahImgFade_xfade() {
    cOpacity = parseFloat(imgs[current].getAttribute("xOpacity"));
	nIndex = imgs[current+1]?current+1:0;

	nOpacity = parseFloat(imgs[nIndex].getAttribute("xOpacity"));
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	imgs[nIndex].style.display = "block";
	imgs[current].setAttribute("xOpacity", cOpacity);
	imgs[nIndex].setAttribute("xOpacity", nOpacity);
	
	setOpacity(imgs[current]); 
	setOpacity(imgs[nIndex]);
	
	if(cOpacity<=0) {
		imgs[current].style.display = "none";
		current = nIndex;
		setTimeout(OdahImgFade_xfade, zInterval);
	} else {
	setTimeout(OdahImgFade_xfade, 50);
	}

	function setOpacity(obj) {
	    opc = parseFloat(obj.getAttribute("xOpacity"));
	    if (opc > 0.99) {
	        obj.setAttribute("xOpacity", "0.99");
			return;
		}
		obj.style.opacity = opc;
		obj.style.MozOpacity = opc;
		obj.style.filter = "alpha(opacity=" + (opc * 100) + ")";
	}
	
}
