// motionDiv 2 - JS Object Development by Raquel,Pepe & Carlos in marchFIRST, 2001
// Añadidos:
//  - gestión de capas anidadas
//  - función para realizar el rollover
//	- compatibilidad con NS 6


		
function motionDiv(tip,obj,child) {
	this.ie=(document.all)? true:false;
	this.nn4=(document.layers)? true:false;
	this.nn6=(!document.all && document.getElementById)? true:false;
	if (this.nn4) {
		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(this.ie){
		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+'"]';
		}
	}else if(nn6){
		this.name = document.getElementById(arguments[1]).style;
		this.nostyle = document.getElementById(arguments[1]);
		this.strName = document.getElementById(arguments[1]);
	}
	this.nameTip = tip;
	this.x = (this.ie) ? this.name.pixelLeft : this.name.left;
	this.y = (this.ie) ? this.name.pixelTop : this.name.top;
	this.w = (this.nn4)? this.name.clip.width : this.nostyle.offsetWidth;
	this.h = (this.nn4)? this.name.clip.height : this.nostyle.offsetHeight;
	this.w2 = (this.nn4)? this.name.width : this.nostyle.scrollWidth;
	this.h2 = (this.nn4)? 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.ident;
	this.direccion;
	this.clasemout;
	this.clasemover;
	this.contenedor;
	this.cadena;
	this.gotoA;
	this.gotoB;
	this.show = motionDivShow;
	this.hide = motionDivHide;
	this.stack = motionDivStack;
	this.paint = motionDivPaint;
	this.resize = motionDivResize;
	this.clip = motionDivClip;
	this.move = motionDivMove;
	this.push = motionDivPush;
	this.fill = motionDivFill;
	this.fader=motionDivFader;
	this.faderGoo=motionDivFaderGoo;
	this.faderHex=motionDivFaderHex;
	this.faderText=motionDivFaderText;
	this.slide = motionDivSlide;
	this.whatToMove = teknoWhatToMoveGoo;
	this.runGoo = teknoWhatToMoveRun;
	this.beizer = motionDivBeizer;
	this.rollover=motionDivrollover;
	this.rolloverOn=motionDivRolloverON;
	this.rolloverOff=motionDivRolloverOFF;
}
function motionDivShow() {
	this.name.visibility = (this.nn4) ? 'show' : 'visible';
}
function motionDivHide() {
	this.name.visibility = (this.nn4) ? 'hide' : 'hidden';
}
function motionDivStack(zI) {
	this.name.zIndex = zI;
}
function motionDivPaint(colH) {
	 (this.nn4)? this.name.bgColor = colH : this.name.backgroundColor = colH;
}
function motionDivResize(x,y) {
	if(this.nn4){
		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 motionDivClip(r,b,t,l) {
	if (this.nn4){
		if (t) this.name.clip.top=t;
		this.name.clip.right=r;
 		this.name.clip.bottom=b;
 		if (l) this.name.clip.left=l;
 	}else{
		if (!t) t=0;
		if (!l) l=0;
 		this.name.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)";
 	}
}
function motionDivMove(x,y) {
	this.x = x;
	this.y = y;
	this.name.left = this.x;
	this.name.top = this.y;
}
function motionDivPush(x,y) {	
	this.x= parseInt(this.x) + x;
	this.y= parseInt(this.y) + y;
	this.name.left = this.x;
	this.name.top = this.y;
}
function motionDivFill(puppet) {
	if (this.nn4) { 
		this.name.document.open();
		this.name.document.write(puppet);
		this.name.document.close();
	}else{
		this.nostyle.innerHTML = puppet;
	}	
}
function motionDivFader(speed,res,i1,i2,i3,f1,f2,f3,text,clase,href,nextEv){
	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;
	this.datFad[4]=nextEv;
	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=href;
	}
	if(clase) this.tfClass=clase;
	this.faderGoo();
}
function motionDivFaderHex(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 motionDivFaderGoo(){
	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]);
	}else{
		if(this.datFad[4]) eval(this.datFad[4]);
	}
}
function makearray(n){
	this.length=n;
	for(var i=1;i<=n;i++) this[i]=0;
	return this;
}
function motionDivFaderText(color){
	if(this.tfHref!=null){
		this.fill("<a href="+this.tfHref+" class="+this.tfClass+"><font color="+color+">"+this.tfText+"</font></a>");
	}else{
		this.fill("<span class="+this.tfClass+"><font color="+color+">"+this.tfText+"</font></span>");
	}
}
function motionDivSlide(xf,yf,resolution,speed,kine,nextEv){
	this.whatToMove(parseInt(this.x),parseInt(this.y),xf,yf,resolution,speed,Math.round(parseInt(this.x)+(xf-parseInt(this.x))/20*(10+kine)),Math.round(parseInt(this.y)+(yf-parseInt(this.y))/20*(10+kine)),'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]);
	}	
}
function motionDivBeizer(xf,yf,resolution,speed,xbeizer,ybeizer,nextEv) {
	this.whatToMove(parseInt(this.x),parseInt(this.y),xf,yf,resolution,speed,xbeizer,ybeizer,'this.move',nextEv);
}
function motionDivrollover(ident,dato1,dato2,dato3,dato4,dato5,dato6){
	this.ident=ident;
	this.contenedor=dato1;
	this.clasemout=dato2;
	this.clasemover=dato3;
	this.direccion=dato4;
	this.gotoA=dato5;
	this.gotoB=dato6;
	eval("div"+this.ident+".rolloverOff('"+this.ident+"','"+this.contenedor+"','"+this.clasemout+"','"+this.clasemover+"','"+this.direccion+"','"+this.gotoA+"','"+this.gotoB+"')");
}
function motionDivRolloverON(ident,dato1,dato2,dato3,dato4,dato5,dato6){
	this.ident=ident;
	this.contenedor=dato1;
	this.clasemout=dato2;
	this.clasemover=dato3;
	this.direccion=dato4;
	this.gotoA=dato5;
	this.gotoB=dato6;
	this.cadena="<a "
	if(dato1!=null) this.cadena+="href='"+this.direccion+"' ";
	if(dato2!=null) this.cadena+="class='"+this.clasemout+"' ";
	if(dato6==null) this.cadena+="onMouseOut=div"+this.ident+".rolloverOff('"+this.ident+"','"+this.contenedor+"','"+this.clasemout+"','"+this.clasemover+"','"+this.direccion+"')";
	else if(dato6!=null) this.cadena+="onMouseOut=div"+this.ident+".rolloverOff('"+this.ident+"','"+this.contenedor+"','"+this.clasemout+"','"+this.clasemover+"','"+this.direccion+"');"+dato5
	this.cadena+=">"+this.contenedor+"</a>"
	this.fill(this.cadena)
}
function motionDivRolloverOFF(ident,dato1,dato2,dato3,dato4,dato5,dato6){
	this.ident=ident;
	this.contenedor=dato1;
	this.clasemout=dato2;
	this.clasemover=dato3;
	this.direccion=dato4;
	this.gotoA=dato5;
	this.gotoB=dato6;
	this.cadena="<a "
	if(dato1!=null) this.cadena+="href='"+this.direccion+"' ";
	if(dato2!=null) this.cadena+="class='"+this.clasemover+"' ";
	if(dato5==null) this.cadena+="onMouseOver=div"+this.ident+".rolloverOn('"+this.ident+"','"+this.contenedor+"','"+this.clasemout+"','"+this.clasemover+"','"+this.direccion+"')";
	else if(dato5!=null) this.cadena+="onMouseOver=div"+this.ident+".rolloverOn('"+this.ident+"','"+this.contenedor+"','"+this.clasemout+"','"+this.clasemover+"','"+this.direccion+"');"+dato5
	this.cadena+=">"+this.contenedor+"</a>"
	this.fill(this.cadena)
}
		
