/*****

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 xFadeBoxId = "xFadeImageContainer";
var imgs = new Array();
var zInterval = null;
var current = 0;
var pause = 2200;
var setVerticalAlign = true;

function so_init() {
	
	// Falls JS aktiv, dann noscript div ausschalten und XFade-Box aktivieren
	noscript = document.getElementById("xFadeNoScript");
	noscript.style.display = "none";
	
	noscript = document.getElementById(xFadeBoxId);
	noscript.style.display = "block";
	
	if(!document.getElementById(xFadeBoxId))return;
	
        // Alle Divs aus dem Container herraussuchen
	imgs = document.getElementById(xFadeBoxId).getElementsByTagName("div");
	counter = document.getElementById(xFadeBoxId).getElementsByTagName("span");
	
	for(i=1;i<imgs.length;i++) { 
           imgs[i].xOpacity = 0; 
        }
	imgs[0].style.display = "block";
	imgs[0].xOpacity = .99;
	counter[0].className = "counter active";

	setTimeout(so_xfade,pause);
}

function so_xfade() {
	cOpacity = imgs[current].xOpacity;
	nIndex = imgs[current+1]?current+1:0;

	nOpacity = imgs[nIndex].xOpacity;
	
	cOpacity-=.02; 
	nOpacity+=.02;
	
	imgs[nIndex].style.display = "block";
	counter[nIndex].className = "counter active";
	counter[current].className = "counter";
	imgs[current].xOpacity = cOpacity;
	imgs[nIndex].xOpacity = nOpacity;
	
	setOpacity(imgs[current]); 
	setOpacity(imgs[nIndex]);
	setOpacity(counter[current]); 
	setOpacity(counter[nIndex]);
	
	if(cOpacity<=0) {
		imgs[current].style.display = "none";
		current = nIndex;
		setTimeout(so_xfade,pause);
	} 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) + ")";
	}
	
}
