// teknoDiv 3.0 - JS Object Development by Emi in Teknoland RTT, 2000

function tkDiv(tip,obj,child) {
	this.nav = (document.layers)? true : false;
	if (this.nav) {
		this.strName = 'document.layers["'+obj+'"]';
		if (child) {
			this.name = document.layers[obj].document.layers[child];
			this.strName += '.document.layers["'+child+'"]';
		} else {
			this.name = document.layers[obj];
		}
	} else {
		if (child) {
			this.name = document.all[child].style;
			this.nostyle = document.all[child];
			this.strName = 'document.all["'+child+'"]';
		} else {
			this.name = document.all[obj].style;
			this.nostyle = document.all[obj];
			this.strName = 'document.all["'+obj+'"]';
		}
	}
	this.nameTip = tip;
	this.x = (this.nav) ? this.name.left : this.name.pixelLeft;
	this.y = (this.nav) ? this.name.top : this.name.pixelTop;
	this.w = (this.nav)? this.name.clip.width : this.nostyle.offsetWidth;
	this.h = (this.nav)? this.name.clip.height : this.nostyle.offsetHeight;
	this.w2 = (this.nav)? this.name.width : this.nostyle.scrollWidth;
	this.h2 = (this.nav)? this.name.height : this.nostyle.scrollHeight;
	this.color = (this.nav)? this.name.bgColor : this.name.backgroundColor;
	this.ov= this.name.overflow;
	this.z = this.name.zIndex;
	this.activo = false;
	this.draging = false;
	this.xdrag = 0;
	this.ydrag = 0;
	this.haveFrame=false;
	this.show = teknoDivShow;
	this.hide = teknoDivHide;
	this.stack = teknoDivStack;
	this.paint = teknoDivPaint;
	this.fader = teknoDivFader;
	this.faderGoo = teknoDivFaderGoo;
	this.faderHex = teknoDivFaderHex;
	this.move = teknoDivMove;
	this.push = teknoDivPush;
	this.resize = teknoDivResize;
	this.fill = teknoDivFill;
	this.mOver = teknoDivMOver;
	this.mOut = teknoDivMOut;
	this.mMove = teknoDivMMove;
	this.mClick = teknoDivMClick;
	this.mUp = teknoDivMUp;
	this.mDown = teknoDivMDown;
	this.slide = teknoDivSlide;
	this.beizer = teknoDivBeizer;
	this.whatToMove = teknoWhatToMoveGoo;
	this.runGoo = teknoWhatToMoveRun;
	this.faderText = teknoDivFaderText;
}



function teknoDivShow() {
	this.name.visibility = (this.nav) ? 'show' : 'visible';
}

function teknoDivHide() {
	this.name.visibility = (this.nav) ? 'hide' : 'hidden';
}

function teknoDivStack(zI) {
	this.name.zIndex = zI;
}

function teknoDivPaint(colH) {
	 (this.nav)? this.name.bgColor = colH : this.name.backgroundColor = colH;
}

function teknoDivFader(speed,res,i1,i2,i3,f1,f2,f3,text,clase,hreff) {
	this.datFad = new Array();
	this.datFad[0] = res;
	this.datFad[1] = 0;
	this.datFad[2] = new Array();
	this.datFad[2][1] = i1;
	this.datFad[2][2] = i2;
	this.datFad[2][3] = i3;
	this.datFad[2][4] = f1;
	this.datFad[2][5] = f2;
	this.datFad[2][6] = f3;
	this.datFad[3] = speed;
	eval(this.nameTip+"hexa = new makearray(16)");
	for(var i = 0; i < 10; i++) eval(this.nameTip+"hexa["+i+"] = "+i);
	eval(this.nameTip+"hexa[10]='a'");
	eval(this.nameTip+"hexa[11]='b'");
	eval(this.nameTip+"hexa[12]='c'");
	eval(this.nameTip+"hexa[13]='d'");
	eval(this.nameTip+"hexa[14]='e'");
	eval(this.nameTip+"hexa[15]='f'");
	this.isText = false;
	if (text) {
		this.tfText = text;
		this.isText = true;
		this.tfHref = hreff;
	}	
	if (clase) this.tfClass = clase;
	this.faderGoo();
}

function teknoDivFaderHex(i) {
	if (i < 0) return "00";
	else if (i > 255) return "ff";
	else return ""+eval(this.nameTip+"hexa[Math.floor("+i+"/16)]")+eval(this.nameTip+"hexa["+i+"%16]");
}

function teknoDivFaderGoo() {
	if (this.datFad[1]<=this.datFad[0]){
		var aux1 = this.datFad[1]/this.datFad[0];
		var aux2 = (this.datFad[0]-this.datFad[1])/this.datFad[0];
		var hr = this.faderHex(Math.floor(this.datFad[2][1]*aux2+this.datFad[2][4]*aux1)); 
		var hg = this.faderHex(Math.floor(this.datFad[2][2]*aux2+this.datFad[2][5]*aux1)); 
		var hb = this.faderHex(Math.floor(this.datFad[2][3]*aux2+this.datFad[2][6]*aux1));
		(this.isText)? this.faderText("#"+hr+hg+hb) : this.paint("#"+hr+hg+hb);
		this.datFad[1]++;
		setTimeout(this.nameTip+".faderGoo()",this.datFad[3]);
	}
}

function makearray(n) {
	this.length = n;
	for(var i = 1; i <= n; i++)	this[i] = 0;
	return this;
}

function teknoDivFaderText(color) {
	this.fill("<a href="+this.tfHref+" class="+this.tfClass+"><font color="+color+">"+this.tfText+"</font></a>");
}

function teknoDivMove(x,y) {
	this.x = x;
	this.y = y;
	this.name.left = this.x;
	this.name.top = this.y;
}

function teknoDivPush(x,y) {	
	this.x += x;
	this.y += y;
	this.name.left = this.x;
	this.name.top = this.y;
}


function teknoDivResize(x,y) {
	if (this.nav) {
		eval(this.strName+'.resizeTo('+x+','+y+')');	
	} else {
		this.name.width = x;
		this.name.height = y;
		this.name.clip = "rect(0px "+x+"px "+y+"px 0px)"
	}
}

function teknoDivFill(puppet) {
	if (this.nav) { 
		this.name.document.open();
		this.name.document.write(puppet);
		this.name.document.close();
	} else {
		this.nostyle.innerHTML = puppet;
	}	
}

function teknoDivMOver(eve) {
	eval(this.strName+".onmouseover = function(event){"+eve+"}");
	if (this.nav) eval(this.strName+'.captureEvents(Event.MOUSEOVER)');
}

function teknoDivMOut(eve) {
	eval(this.strName+".onmouseout = function(event){"+eve+"}");
	if (this.nav) eval(this.strName+'.captureEvents(Event.MOUSEOUT)');
}

function teknoDivMMove(eve) {
	eval(this.strName+".onmousemove = function(event){"+eve+"}");
	if (this.nav) eval(this.strName+'.captureEvents(Event.MOUSEMOVE)');
}

function teknoDivMClick(eve) {
	eval(this.strName+".onclick = function(event){"+eve+"}");
	if (this.nav) eval(this.strName+'.captureEvents(Event.CLICK)');
}

function teknoDivMUp(eve) {
	eval(this.strName+".onmouseup = function(event){"+eve+"}");
	if (this.nav) eval(this.strName+'.captureEvents(Event.MOUSEUP)');
}

function teknoDivMDown(eve) {
	eval(this.strName+".onmousedown = function(event){"+eve+"}");
	if (this.nav) eval(this.strName+'.captureEvents(Event.MOUSEDOWN)');
}



function teknoDivSlide(xf,yf,resolution,speed,kine,nextEv) {
	this.whatToMove(this.x,this.y,xf,yf,resolution,speed,Math.round(this.x+(xf-this.x)/20*(10+kine)),Math.round(this.y+(yf-this.y)/20*(10+kine)),'this.move',nextEv);
}

function teknoDivBeizer(xf,yf,resolution,speed,xbeizer,ybeizer,nextEv) {
	this.whatToMove(this.x,this.y,xf,yf,resolution,speed,xbeizer,ybeizer,'this.move',nextEv);
}
	
function teknoWhatToMoveGoo(xi,yi,xf,yf,resolution,speed,xbeizer,ybeizer,func,nextEv) {
	this.datGoo = new Array();
	this.datGoo[0] = resolution+1;
	this.datGoo[1] = speed;
	this.datGoo[2] = 1;
	this.datGoo[3] = 0;
	this.datGoo[4] = 1/resolution;
	this.datGoo[5] = func;
	this.datGoo[6] = nextEv;
	this.datGoo[7] = new Array();
	this.datGoo[8] = new Array();
	for (i=1;i<=this.datGoo[0];i++){
		var auxS0 = 1-this.datGoo[3];
		var auxS1 = auxS0 * auxS0;
		var auxS2 = this.datGoo[3] * this.datGoo[3];
		var auxS3 = 2 * this.datGoo[3] * auxS0; 
		this.datGoo[7][i] = Math.round((auxS1*xi)+(auxS3*xbeizer)+(auxS2*xf));
		this.datGoo[8][i] = Math.round((auxS1*yi)+(auxS3*ybeizer)+(auxS2*yf));
		this.datGoo[3] = i * this.datGoo[4];	
	}
	this.runGoo();
}

function teknoWhatToMoveRun() {
	if (this.datGoo[2] <= this.datGoo[0]) {
		eval(this.datGoo[5]+'('+this.datGoo[7][this.datGoo[2]]+','+this.datGoo[8][this.datGoo[2]]+')');
		this.datGoo[2]++;
		setTimeout(this.nameTip+".runGoo()",this.datGoo[1]);		
	} else { 
		if (this.datGoo[6]) eval(this.datGoo[6]);
	}	
}