﻿var ObjIni = 'divid';
var Objcnt = 12;
var curobj = 1;
function nextobjid(befobj){
    if(befobj >= Objcnt){
        curobj = 1;
    }
    else
    {
        curobj = parseInt(befobj) + 1;
    }
    return ObjIni + curobj;
}

function fadeIn(ObjId,speed,step){	    
	var Obj = document.getElementById(ObjId);	
	Obj.style.display = "block";
	//if(Obj.style.display=="block"){
		var currOp = getOpacity(Obj);		
		if(isNaN(currOp)){
		    currOp = 0;
		}
		if(currOp<100){
			clearTimeout(Obj.FadeTimeout);
			setOpacity(Obj, (currOp + step));
			Obj.FadeTimeout = setTimeout("fadeIn('" + ObjId + "'," + speed + "," + step + ");", speed);
		}else{
		    Obj.FadeTimeout = setTimeout("fadeOut('" + ObjId + "'," + speed + "," + step + ");", speed);
		}
	//}
}

function fadeOut(ObjId,speed,step){	
	var Obj = document.getElementById(ObjId);
	Obj.style.display = "block";
	//if(Obj.style.display=="block"){
		var currOp = getOpacity(Obj);
		if(isNaN(currOp)){
		    currOp = 100;
		}
		if(currOp>0){
			clearTimeout(Obj.FadeTimeout);
			setOpacity(Obj, (currOp - step));
			Obj.FadeTimeout = setTimeout("fadeOut('" + ObjId + "'," + speed + "," + step + ");", speed);
		}else{
		        Obj.style.display = "none";
			    Obj.FadeTimeout = setTimeout("fadeIn('" + nextobjid(curobj) + "'," + speed + "," + step + ");", speed);
			//Obj.style.display="none";
		}
	//}
}
function setOpacity(Obj,TranPer){	
    var object = Obj.style;
    opacity = TranPer;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
	//Obj.style.filter= "alpha(opacity=" + TranPer + ")";
	//Obj.style.MozOpacity=TranPer/100;
}

// The Following function gets the transperancy of an object in percent
function getOpacity(Obj){
	if(/MSIE/.test(navigator.userAgent))
		originalOpacity = parseInt(Obj.style.filter.replace(/alpha\(opacity=([0-9]{1,3})\)/g, '$1'), 10);
	else
		originalOpacity = parseInt(Obj.style.MozOpacity * 100, 10);

	if (isNaN(originalOpacity))
		originalOpacity = NaN;
		
	return originalOpacity;
}