
var treeImgBoxes = new Array();
var d=document;
var fadebox = new Array();
var zInterval = null;
var pause=false;
var secFocus = 6000;



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);
		}
		fadebox = new Array();
		}
}


function so_xfade(imgs,timeout) {
	if(timeout){
		 setTimeout(function(){so_xfade(imgs);},5000);
		 return true;
	}
	var prntObj = imgs[0].parentNode;
	var current_tif = prntObj.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";
		prntObj.setAttribute("current_tif", nIndex);
		imgs[current_tif].setAttribute("xOpacity", 0);
	
		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;

	var objChild = obj.firstChild;
	if(objChild.nodeName == "A"){
		objChild = objChild.firstChild;
	}
	
	objChild.style.filter = 'alpha(opacity=' + Math.round(obj.xOpacity*100) + ')';
	
}

