/*****

Image Cross Fade Redux
Version 1.0

Last revision: 02.15.2006
steve@slayeroffice.com

Last revision: 12.08.2007
fader background added
machiko.murakami@marqui.com

Last revision: 06.06.2008
image + text can be in a holder <div>
machiko.murakami@marqui.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 d=document, holder = new Array(), current=0;

function so_init(id, tag) {	
	holder = d.getElementById(id).getElementsByTagName(tag);
	
	// take care of Mac - none-display
	for(i=0;i<holder.length;i++){
	    if(i!=0){
			holder[i].xOpacity = 0;
	   		holder[i].style.display = "none";	 
		}
		holder[i].style.position='absolute';
	}
	
	// display only the first pic, and background the second pic
	holder[0].style.display = "block";
	holder[0].xOpacity = .99;
	
	setTimeout(so_xfade,10000);
}

function so_xfade() {
	cOpacity = holder[current].xOpacity;
	nIndex = holder[current+1]?current+1:0;

	nOpacity = holder[nIndex].xOpacity;
	
	cOpacity-=.05; 
	nOpacity+=.05;
	
	// place the background to the next one
	holder[nIndex].style.display='block';
	holder[current].xOpacity = cOpacity;
	holder[nIndex].xOpacity = nOpacity;
	
	setOpacity(holder[current]); 
	setOpacity(holder[nIndex]);
	
	if(cOpacity<=0) {
		holder[current].style.display = "none";
		if(holder[current+1]) holder[current+1].style.display = "block";
		else holder[0].style.display = "block"
		
		current = nIndex;
		setTimeout(so_xfade,10000);
	} else {
		setTimeout(so_xfade,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) + ")";
	}
	
}