// .arena v2.0 
// .fader (01.04.01) [precisa de .math]
// (C) Copyright 2001 por Emiliano Benítez, Israel Pastrana
// Prohibido su uso o distribucion en su totalidad o en parte del codigo sin autorizacion del autor.

arena.arenaIns.prototype.faderText = function(spd,res,icolor,fcolor,text,clase,onEnd) {	this.fader(spd,res,null,null,text,clase,icolor,fcolor,onEnd); }

arena.arenaIns.prototype.faderBG = function(spd,res,icolor,fcolor,onEnd) { this.fader(spd,res,icolor,fcolor,null,null,null,null,onEnd); }

arena.arenaIns.prototype.fader = function(spd,res,icolor,fcolor,text,clase,itcolor,ftcolor,onEnd) {
	this.timeFad = 0;
	this.typeFad = [icolor,itcolor];
	this.datFad = [res,0,arena.speed(spd),onEnd];
	if (this.typeFad[0]){
		this.datFad[4] = eval("["+(this.faderMData(icolor,fcolor))+"]");
		this.datFad[5] = [];
	}			
	if (this.typeFad[1]){
		this.datTextFad = [text,clase];
		this.datTextFad[4] = eval("["+(this.faderMData(itcolor,ftcolor))+"]");
		this.datTextFad[5] = [];	
	}
	for (i=1;i<=this.datFad[0];i++){
		this.datFad[1] = i;
		if (this.typeFad[0]) this.datFad[5][i] = this.faderColor(this.datFad);
		if (this.typeFad[1]) this.datTextFad[5][i] = this.faderColor(this.datTextFad);
	}
	this.replayFader();
}

arena.arenaIns.prototype.replayFader = function(){
	this.datFad[1] = 0;
	clearTimeout(this.timeFad);
	this.faderGoo();
}

arena.arenaIns.prototype.faderMData = function(ic,fc){ return ""+parseInt("0x"+ic.substr(1,2),16)+","+parseInt("0x"+ic.substr(3,2),16)+","+parseInt("0x"+ic.substr(5,2),16)+","+(parseInt("0x"+fc.substr(1,2),16)-parseInt("0x"+ic.substr(1,2),16))/this.datFad[0]+","+(parseInt("0x"+fc.substr(3,2),16)-parseInt("0x"+ic.substr(3,2),16))/this.datFad[0]+","+(parseInt("0x"+fc.substr(5,2),16)-parseInt("0x"+ic.substr(5,2),16))/this.datFad[0]; }
	
arena.arenaIns.prototype.faderColor = function(aDt){ return '#'+arena.decToHex(Math.round(aDt[4][0]+this.datFad[1]*aDt[4][3]))+arena.decToHex(Math.round(aDt[4][1]+this.datFad[1]*aDt[4][4]))+arena.decToHex(Math.round(aDt[4][2]+this.datFad[1]*aDt[4][5])); }

arena.arenaIns.prototype.faderGoo = function() {
	if (++this.datFad[1]<=this.datFad[0]){
		if (this.typeFad[0]) this.color(this.datFad[5][this.datFad[1]]);
		if (this.typeFad[1]) this.fill("<div align=center><font class="+this.datTextFad[1]+"><font color="+(this.datTextFad[5][this.datFad[1]])+">"+this.datTextFad[0]+"</font></font></div>");
		this.timeFad=setTimeout(this.id+".faderGoo()",this.datFad[2]);
	} else if (this.datFad[3]) eval(this.datFad[3]);
}
