/*****
Based on: http://slayeroffice.com/code/imageCrossFade/xfade2.html
Altered by Jesse to remove css importing
To alter the fade speed alter the 2 lines that look like this: setTimeout(so_xfade,2000); (change the "2000" to the desired fade time in ms)
*****/

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

var d=document, 
	imgs_left = new Array(), 
	imgs_center = new Array(), 
	imgs_right = new Array(), 
	zInterval = null, 
	current_left=0, 
	current_center=0, 
	current_right=0, 
	pause=false;

function so_init() {
        if(!d.getElementById || !d.createElement)return;

        imgs_center = d.getElementById("imgCenter").getElementsByTagName("img");
        imgs_left = d.getElementById("imgLeft").getElementsByTagName("img");
        imgs_right = d.getElementById("imgRight").getElementsByTagName("img");
        
        for(i=1;i<imgs_left.length;i++) {imgs_left[i].xOpacity = 0;}
        imgs_left[0].style.display = "block";
        imgs_left[0].xOpacity = .99;
        
        for(i=1;i<imgs_right.length;i++) {imgs_right[i].xOpacity = 0;}
        imgs_right[0].style.display = "block";
        imgs_right[0].xOpacity = .99;
        
        for(i=1;i<imgs_center.length;i++) {imgs_center[i].xOpacity = 0;}
        imgs_center[0].style.display = "block";
        imgs_center[0].xOpacity = .99;

        setTimeout(so_xfade_left,2000);
        
        setTimeout(so_xfade_center,4000);
        
        setTimeout(so_xfade_right,6000);                
}

function so_xfade_left() {
        cOpacity = imgs_left[current_left].xOpacity;
        nIndex = imgs_left[current_left+1]?current_left+1:0;

        nOpacity = imgs_left[nIndex].xOpacity;

        cOpacity-=.05;
        nOpacity+=.05;

        imgs_left[nIndex].style.display = "block";
        imgs_left[current_left].xOpacity = cOpacity;
        imgs_left[nIndex].xOpacity = nOpacity;

        setOpacity(imgs_left[current_left]);
        setOpacity(imgs_left[nIndex]);

        if(cOpacity<=0) {
                imgs_left[current_left].style.display = "none";
                current_left = nIndex;
                setTimeout(so_xfade_left,6000);
        } else {
                setTimeout(so_xfade_left,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 so_xfade_center() {
	cOpacity = imgs_center[current_center].xOpacity;
	nIndex = imgs_center[current_center+1]?current_center+1:0;
	
	nOpacity = imgs_center[nIndex].xOpacity;
	
	cOpacity-=.05;
	nOpacity+=.05;
	
	imgs_center[nIndex].style.display = "block";
	imgs_center[current_center].xOpacity = cOpacity;
	imgs_center[nIndex].xOpacity = nOpacity;
	
	setOpacity(imgs_center[current_center]);
	setOpacity(imgs_center[nIndex]);
	
	if(cOpacity<=0) {
		imgs_center[current_center].style.display = "none";
		current_center = nIndex;
		setTimeout(so_xfade_center,6000);
	} else {
		setTimeout(so_xfade_center,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 so_xfade_right() {
	cOpacity = imgs_right[current_right].xOpacity;
	nIndex = imgs_right[current_right+1]?current_right+1:0;
	
	nOpacity = imgs_right[nIndex].xOpacity;
	
	cOpacity-=.05;
	nOpacity+=.05;
	
	imgs_right[nIndex].style.display = "block";
	imgs_right[current_right].xOpacity = cOpacity;
	imgs_right[nIndex].xOpacity = nOpacity;
	
	setOpacity(imgs_right[current_right]);
	setOpacity(imgs_right[nIndex]);
	
	if(cOpacity<=0) {
		imgs_right[current_right].style.display = "none";
		current_right = nIndex;
		setTimeout(so_xfade_right,6000);
	} else {
		setTimeout(so_xfade_right,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) + ")";
	}
}