if(window.addEventListener) {
	window.addEventListener("load",treeImage_init,false);
} else {
	window.attachEvent("onload",treeImage_init);
}


//define here the divs which store the images;
var treeImgBoxes = new Array();
var d=document;
var fadebox = new Array();
var zInterval = null;
var pause=false;
var secFocus = 5000;


function setTreeLink(objRel){
	var setLink = objRel.getAttribute("rel");
	clObj = d.getElementById(objRel.parentNode.id + "_skin");
	clObj.style.cursor = "default";
	clObj.setAttribute("rel", null);
	if(setLink != null && setLink != 0){
		clObj.style.cursor = "pointer";
		clObj.setAttribute("rel", setLink);
	}
}

function treeImage_init() {
	if(!d.getElementById || !d.createElement) return;

	for(var i = 0;i < treeImgBoxes.length ; i++){
		var bid = treeImgBoxes[i];
	 
		fadebox = d.getElementById(bid).getElementsByTagName("div");
		if(fadebox.length > 0){
			for(var u=1;u<fadebox.length;u++) fadebox[u].setAttribute("xOpacity", 0);
			fadebox[0].style.display = "block";
			fadebox[0].setAttribute("xOpacity", "0.99");
			fadebox[0].parentNode.setAttribute("current_tif","0");
			so_xfade(fadebox, true);
		
			setTreeLink(fadebox[0]);
			//when a link is added clicking on it will help :)
			d.getElementById(bid + "_skin").onclick = function(){ 
				var newLink = this.getAttribute('rel');
				if(newLink) location.href = newLink;
				}
		}
		fadebox = new Array();
		}
}

function so_xfade(imgs,timeout) {
	if(timeout){
		 setTimeout(function(){so_xfade(imgs);},5000);
		 return true;
	}
	var current_tif = imgs[0].parentNode.getAttribute("current_tif");
	
	cOpacity = imgs[current_tif].getAttribute("xOpacity");
	var newNumber = parseFloat(parseInt(current_tif)+1);
	nIndex = imgs[newNumber]?newNumber:0;

	
	nOpacity = parseFloat(imgs[nIndex].getAttribute("xOpacity"));
	cOpacity = (parseFloat(cOpacity - 0.05)).toFixed(2); 
	nOpacity = (parseFloat(nOpacity + 0.05)).toFixed(2);



	imgs[nIndex].style.display = "block";
	imgs[current_tif].setAttribute("xOpacity", cOpacity);
	imgs[nIndex].setAttribute("xOpacity", nOpacity);
	
	setOpacity(imgs[current_tif]); 
	setOpacity(imgs[nIndex]);

	if(cOpacity<=0) {
		imgs[current_tif].style.display = "none";
		imgs[0].parentNode.setAttribute("current_tif", nIndex);
		imgs[current_tif].setAttribute("xOpacity", 0);
		setTreeLink(imgs[nIndex]);
		/*
		var setLink = imgs[nIndex].getAttribute("rel");
		clObj = d.getElementById(imgs[0].parentNode.id + "_skin");
		clObj.style.cursor = "default";
		clObj.setAttribute("rel", null);
		if(setLink != null && setLink != 0){
			clObj.style.cursor = "pointer";
			clObj.setAttribute("rel", setLink);
		}
		*/
	
		setTimeout(function() {so_xfade(imgs)}, secFocus);
	} else 
		setTimeout(function() {so_xfade(imgs)},50);
	
}


function setOpacity(obj) {
	var xOpacity = parseFloat(obj.getAttribute("xOpacity"));

	if(xOpacity > 0.99){
		obj.setAttribute("xOpacity", 0.99 );
		return;
	}
	
	obj.style.opacity = xOpacity;
	obj.style.MozOpacity = xOpacity;
	obj.firstChild.style.filter = 'alpha(opacity=' + Math.round(obj.xOpacity*100) + ')';
}
/**********************************************

	
	
	CSS styles die toegevoegd moeten worden
	


#imageContainer {
	height: 158px;
	width: 774px;
	position:relative;
	margin-left:195px;
	_margin-left:0px;
	_position:absolute;
	
}
#imageContainer div{
	display:none;
	position:absolute;
	top:0;
	left:0px;
	:left:0px;
}
**********************************************/
