// JavaScript Document

/*

Image Cross Fade Redux
Original Author: steve@slayeroffice.com
Modified by: Chris Wheeler
New Modified by: Damian Desia

Please leave this notice intact.

*/
	window.addEventListener?window.addEventListener("load",init,false):window.attachEvent("onload",init);/*
	window.addEventListener?window.addEventListener("load",init2,false):window.attachEvent("onload",init2);
	window.addEventListener?window.addEventListener("load",init3,false):window.attachEvent("onload",init3);*/

var d=document, container, container2, container3, imgs = new Array(), imgs2 = new Array(), imgs3 = new Array(), zInterval = null, current=0, current2=0, current3=0, pause=false;

function init() {
        if(!d.getElementById || !d.createElement) return;
        container = d.getElementById("fxtoimgs");
        /* If javascript is enabled, remove static background image */
        container.style.backgroundImage="none";
        imgs = container.getElementsByTagName("img");
        for(i=1; i<imgs.length; i++) imgs[i].xOpacity = 0;
        imgs[0].style.display = "block";
        imgs[0].xOpacity = 1;
        setTimeout(xfade,3000);
}
/*
function init2() {
        if(!d.getElementById || !d.createElement) return;
        container2 = d.getElementById("fxtoimgs2");
        container2.style.backgroundImage="none";
        imgs2 = container2.getElementsByTagName("img");
        for(i=1; i<imgs2.length; i++) imgs2[i].xOpacity = 0;
        imgs2[0].style.display = "block";
        imgs2[0].xOpacity = 1;
        setTimeout(xfade2,3000);
}

function init3() {
        if(!d.getElementById || !d.createElement) return;
        container3 = d.getElementById("fxtoimgs3");
        container3.style.backgroundImage="none";
        imgs3 = container3.getElementsByTagName("img");
        for(i=1; i<imgs3.length; i++) imgs3[i].xOpacity = 0;
        imgs3[0].style.display = "block";
        imgs3[0].xOpacity = 1;
        setTimeout(xfade3,3000);
}*/

function xfade() {
        cOpacity = imgs[current].xOpacity;
        nIndex = imgs[current+1]?current+1:0;
        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;
                setTimeout(xfade,3000);
        } else {
                setTimeout(xfade,50);
        }

        function setOpacity(obj) {
                if(obj.xOpacity > 1) {
                        obj.xOpacity = 1;
                        return;
                }
				obj.style.KHTMLOpacity = obj.xOpacity;
                obj.style.opacity = obj.xOpacity;
                obj.style.MozOpacity = obj.xOpacity;
                obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
        }

}

function xfade2() {
        cOpacity = imgs2[current2].xOpacity;
        nIndex = imgs2[current2+1]?current2+1:0;
        nOpacity = imgs2[nIndex].xOpacity;

        cOpacity-=.05;
        nOpacity+=.05;

        imgs2[nIndex].style.display = "block";
        imgs2[current2].xOpacity = cOpacity;
        imgs2[nIndex].xOpacity = nOpacity;

        setOpacity2(imgs2[current2]);
        setOpacity2(imgs2[nIndex]);

        if(cOpacity<=0) {
                imgs2[current2].style.display = "none";
                current2 = nIndex;
                setTimeout(xfade2,3000);
        } else {
                setTimeout(xfade2,50);
        }

        function setOpacity2(obj) {
                if(obj.xOpacity > 1) {
                        obj.xOpacity = 1;
                        return;
                }
				obj.style.KHTMLOpacity = obj.xOpacity;
                obj.style.opacity = obj.xOpacity;
                obj.style.MozOpacity = obj.xOpacity;
                obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
        }

}

function xfade3() {
        cOpacity = imgs3[current3].xOpacity;
        nIndex = imgs3[current3+1]?current3+1:0;
        nOpacity = imgs3[nIndex].xOpacity;

        cOpacity-=.05;
        nOpacity+=.05;

        imgs3[nIndex].style.display = "block";
        imgs3[current3].xOpacity = cOpacity;
        imgs3[nIndex].xOpacity = nOpacity;

        setOpacity3(imgs3[current3]);
        setOpacity3(imgs3[nIndex]);

        if(cOpacity<=0) {
                imgs3[current3].style.display = "none";
                current3 = nIndex;
                setTimeout(xfade3,3000);
        } else {
                setTimeout(xfade3,50);
        }

        function setOpacity3(obj) {
                if(obj.xOpacity > 1) {
                        obj.xOpacity = 1;
                        return;
                }
				obj.style.KHTMLOpacity = obj.xOpacity;
                obj.style.opacity = obj.xOpacity;
                obj.style.MozOpacity = obj.xOpacity;
                obj.style.filter = "alpha(opacity=" + (obj.xOpacity*100) + ")";
        }

}
