/*****
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_ads,false):window.attachEvent("onload",so_init_ads);

var d_ads=document, imgs_ads = new Array(), zInterval = null, current_ads=0, pause=false, k=0;

function so_init_ads() {
	if(!d_ads.getElementById || !d_ads.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
	//css = d_ads.createElement("link");
	//css.setAttribute("href","xfade2.css");
	//css.setAttribute("rel","stylesheet");
	//css.setAttribute("type","text/css");
	//d_ads.getElementsByTagName("head")[0].appendChild(css);

	imgs_ads = d_ads.getElementById("advertiseImage").getElementsByTagName("img");
	for(i=0;i<imgs_ads.length;i++) imgs_ads[i].xOpacity = 0;
	imgs_ads[0].style.display = "block";
	imgs_ads[0].xOpacity = 1;
	
	setTimeout(so_xfade_ads,3000);
}

function so_xfade_ads() {
	cOpacity_ads = imgs_ads[current_ads].xOpacity;
	nIndex_ads = imgs_ads[current_ads+1]?current_ads+1:0;

	nOpacity_ads = imgs_ads[nIndex_ads].xOpacity;
	
	cOpacity_ads-=.05; 
	nOpacity_ads+=.05;
	
	imgs_ads[nIndex_ads].style.display = "block";
	imgs_ads[current_ads].xOpacity = cOpacity_ads;
	imgs_ads[nIndex_ads].xOpacity = nOpacity_ads;
	
	setOpacity(imgs_ads[current_ads]); 
	setOpacity(imgs_ads[nIndex_ads]);
	
	if(cOpacity_ads<=0) {
		imgs_ads[current_ads].style.display = "none";
		current_ads = nIndex_ads;
		setTimeout(so_xfade_ads,5000);
	} else {
		setTimeout(so_xfade_ads,80);
	}
	
	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) + ")";
	}
	
}