var oTrans = new Array(100)
var y = ""

function getTransIndex(oObject) {
	nTx = -1
	for (i=0; i<oTrans.length; i++) {		
		if (oTrans[i] != null) {
			if (oTrans[i].oObject == oObject) {
				nTx = i
			}
		} else {
			if (nTx < 0) {
				nTx = i
			}
		}
	}
	return nTx
}

function doFocus(oObject, sProperty, sColorStart, sColorEnd, nTransitionMax, nTransitionPause)
{
	var nTx = getTransIndex(oObject)
	if (oTrans[nTx] == null || oTrans[nTx] == 'undefined') {
		oTrans[nTx] = new liga(oObject, nTx, sProperty, sColorStart, sColorEnd, nTransitionMax, nTransitionPause)	
	} else {		
		oTrans[nTx].nTransitionInc = 1
	}
}

function doBlur(oObject)
{
	var nTx = getTransIndex(oObject)
	if (oTrans[nTx] != null && oTrans[nTx] != 'undefined') {
		oTrans[nTx].desliga()
	}
}

function liga(obj, nTx, sProperty, sColorStart, sColorEnd, nTransitionMax, nTransitionPause)
 {
	this.nTransitionMax = nTransitionMax
	this.oObject = obj
	this.nTx = nTx
	if (this.nTransition < 0 || isNaN(this.nTransition)) this.nTransition = 0
	if (this.nTransition > this.nTransitionMax) this.nTransition = this.nTransitionMax
	this.nTransitionInc = 1
	this.sProperty = sProperty
	this.sColorStart = sColorStart
	this.sColorEnd = sColorEnd
	this.nTransitionPause = nTransitionPause
	this.transicao = transicao
	this.desliga = desliga

	this.oObject.style.cursor = 'hand'
	
	this.transicao()

	return this
}

function desliga()
{
	if (this.nTransition < 0) this.nTransition = 0
	if (this.nTransition > this.nTransitionMax) this.nTransition = this.nTransitionMax
	this.oObject.style.cursor = ''
	this.nTransitionInc = -1
	this.transicao()
}

function transicao()
{
	if ((this.nTransition > 0 && this.nTransitionInc < 0) || (this.nTransition < this.nTransitionMax && this.nTransitionInc > 0)) {
		this.nTransition += this.nTransitionInc
		if (this.nTransition < 0) {
			sColor = sColorStart
		} else {
			if (this.nTransition > this.nTransitionMax) {
				sColor = sColorEnd
			} else {
				var nColorStartR = Number('0x' + this.sColorStart.substr(1,2))
				var nColorStartG = Number('0x' + this.sColorStart.substr(3,2))
				var nColorStartB = Number('0x' + this.sColorStart.substr(5,2))

				var nColorEndR = Number('0x' + this.sColorEnd.substr(1,2))
				var nColorEndG = Number('0x' + this.sColorEnd.substr(3,2))
				var nColorEndB = Number('0x' + this.sColorEnd.substr(5,2))

				if (nColorStartR < nColorEndR) {
					nColorR = Math.round(nColorStartR + this.nTransition*(nColorEndR-nColorStartR)/this.nTransitionMax)
				} else {
					nColorR = Math.round(nColorStartR - this.nTransition*(nColorStartR-nColorEndR)/this.nTransitionMax)
				}

				if (nColorStartG < nColorEndG) {
					nColorG = Math.round(nColorStartG + this.nTransition*(nColorEndG-nColorStartG)/this.nTransitionMax)
				} else {
					nColorG = Math.round(nColorStartG - this.nTransition*(nColorStartG-nColorEndG)/this.nTransitionMax)
				}

				if (nColorStartB < nColorEndB) {
					nColorB = Math.round(nColorStartB + this.nTransition*(nColorEndB-nColorStartB)/this.nTransitionMax)
				} else {
					nColorB = Math.round(nColorStartB - this.nTransition*(nColorStartB-nColorEndB)/this.nTransitionMax)
				}

		
				sColor = '0' + nColorR.toString(16)
				sColorR = sColor.substr(sColor.length-2, 2)

				sColor = '0' + nColorG.toString(16)
				sColorG = sColor.substr(sColor.length-2, 2)

				sColor = '0' + nColorB.toString(16)
				sColorB = sColor.substr(sColor.length-2, 2)

				sColor = '#' + sColorR + sColorG + sColorB

				//window.status = '' + sColor
			}
		}
		

		//window.status = '' + this.nTransition + ' ' + x
		
		//var obj = eval("this.oObject.style." + this.sProperty)		
		//obj = sColor
		//alert(this.oObject.style.background)
		//this.oObject.style.setAttribute(this.sProperty, sColor)
		switch (this.sProperty) 
		{
			case 'color':
				this.oObject.style.color = sColor
				break;
			case 'background':
			default:				
				this.oObject.style.background = sColor
				break;			
		}		

		timerID = window.setTimeout('transicao2(' + this.nTx + ')', this.nTransitionPause)
	} else {
		if (this.nTransition <= 0) {
			oTrans[this.nTx] = null
		}

	}

}

function transicao2(nTx)
{	
	if (oTrans[nTx] != null && oTrans[nTx] != 'undefined') {
		oTrans[nTx].transicao()
	}
}

	//PRELOADER
	function loadImages() 
	{		
	    for (var i = 0; i < arguments.length; i++) {
	        var temp = makeId(arguments[i]);
	        eval(temp +"= new Image()");
	        eval(temp+".src ='"+ arguments[i] +"'");
	    }
	}
	        
	function makeId(path) 
	{
	    return "preload_"  + path.substring( path.lastIndexOf("/")+1, path.lastIndexOf("."));
	}

	function loadAllImages()
	{
         loadImages("/DesktopModules/PC_Graficos/images/1level.gif",
                    "/DesktopModules/PC_Graficos/images/at.gif",
                    "/DesktopModules/PC_Graficos/images/exit.gif",
                    "/DesktopModules/PC_Graficos/images/help.gif",
                    "/DesktopModules/PC_Graficos/images/key.gif",
                    "/DesktopModules/PC_Graficos/images/new.gif",
                    "/DesktopModules/PC_Graficos/images/user2.gif",
                    "/DesktopModules/PC_Graficos/images/user.gif",
                    "/DesktopModules/PC_Graficos/images/vis4o.gif",
                    "/DesktopModules/PC_Graficos/images/vis3o.gif",
                    "/DesktopModules/PC_Graficos/images/vis2o.gif",
                    "/DesktopModules/PC_Graficos/images/vis1o.gif",
                    "/DesktopModules/PC_Graficos/images/vis4.gif",
                    "/DesktopModules/PC_Graficos/images/vis3.gif",
                    "/DesktopModules/PC_Graficos/images/vis2.gif",
                    "/DesktopModules/PC_Graficos/images/vis1.gif"
                    );
                    
          // other code called onload goes here.
    }       


