// Mundilayers
// (c) 1999 Fernando Sengáriz
// Dpto. Diseño
// Mundivía, S.A.
// 01-02-1999

function MundiCapa(capa) {
	if (ns4) {
		this.estilo = document.layers[capa];
		this.x = this.estilo.left;
		this.y = this.estilo.top;
	}
	else if (ie4) {
		this.estilo = document.all[capa].style;
		this.x = this.estilo.pixelLeft;
		this.y = this.estilo.pixelTop;
	}
	this.event = (ns4) ? this.estilo : document.all[capa];
	this.obj = capa + "MundiCapa";
	this.texto = (ns4) ? this.estilo.document : this.event;
	eval(this.obj + "=this");
	this.capa = capa;
	this.w = (ns4) ? this.estilo.clip.width : this.estilo.pixelWidth;
	this.h = (ns4) ? this.estilo.clip.height : this.event.scrollHeight;
	this.z = this.estilo.zIndex;
	this.scrollh = this.h;
	this.subeA = MundiCapaSubeA;
	this.ajustaA = MundiCapaAjustaA;
	this.mueveA = MundiCapaColocaEn;
	this.desplazaEn = MundiCapaDesplazaEn;
	this.muestra = MundiCapaMuestra;
	this.oculta = MundiCapaOculta;
	this.escribe = MundiCapaEscribe;
	this.setArrastraEn = MundiCapaArrastraEnInit;
	this.arrastraEn = MundiCapaArrastraEn;
	this.arrastra = MundiCapaArrastra;
	this.creaContenido = MundiCapaCreaContenido;
	this.cargaPagina = MundiCapaCargaPagina;
	this.clipA = MundiCapaClipA;
	this.agrandaEn = MundiCapaAgrandaEn;
	this.agranda = MundiCapaAgranda;
}
function MundiCapaCreaContenido () {
	this.contenido = this.capa + "MundiContenido";
	if (ns4) {
		//this.escribe("<layer id='"+this.capa+"Contenido"+"' WIDTH=175 HEIGHT=175 MARGINWIDTH=0 MARGINHEIGHT=0 SCROLLING='NO' FRAMEBORDER='NO'></layer>");
		//eval(this.contenido+"=document."+this.capa+".document."+this.capa+"Contenido");
		eval(this.contenido+"=this.event");
	}
	if (ie4) {
		this.escribe("<iframe id='"+this.capa+"Contenido"+"' WIDTH="+this.w+" HEIGHT="+this.h+" MARGINWIDTH=0 MARGINHEIGHT=0 SCROLLING='NO' FRAMEBORDER='NO'></IFRAME>");
		eval(this.contenido+"=document.all."+this.capa+"Contenido");
	}
}
function MundiCapaCargaPagina (url) {
	eval(this.contenido).src=url;
}
function MundiCapaEscribe (texto_html) {
	if (ns4) {
		this.texto.open();
		this.texto.write(texto_html);
		this.texto.close();
	}
	else if (ie4) {
		this.texto.innerHTML = texto_html;
	}
}
function MundiCapaSubeA (z) {
	if (z!=null) {
		this.z = z;
		this.estilo.zIndex = z;
	}
}
function MundiCapaAjustaA (new_w, new_h) {
	if (new_w!=null) {
		this.w = new_w;
		if (ns4) this.estilo.clip.width = this.w;
		if (ie4) this.estilo.pixelWidth = this.w;
	}
	if (new_h!=null) {
		this.h = new_h;
		if (ns4) this.estilo.clip.height = this.h;
		if (ie4) this.estilo.pixelHeight = this.h;
	}
}
function MundiCapaColocaEn(x,y) {
	if (x!=null) {
		this.x = x;
		this.estilo.left = this.x;
	}
	if (y!=null) {
		this.y = y;
		this.estilo.top = this.y;
	}
}
function MundiCapaDesplazaEn(x,y) {
	if (x==null) x = 0;
	if (y==null) y = 0;
	this.mueveA(this.x+x,this.y+y);
}
function MundiCapaMuestra() {
	this.estilo.visibility = (ns4)? "show" : "visible";
}
function MundiCapaOculta() {
	this.estilo.visibility = (ns4)? "hide" : "hidden";
}
function MundiCapaSubeA (z) {
	if (z!=null) {
		this.z = z;
		this.estilo.zIndex = z;
	}
}
function MundiCapaArrastraEnInit () {
	this.arrastraEn = MundiCapaArrastraEn;
	this.arrastra = MundiCapaArrastra;
}
function MundiCapaArrastraEn ( xdist, ydist, inc, velocidad, f_funcion) {
	if ( this.arrastrando ) return
	if (!inc) inc = 20;
	if (!velocidad) velocidad = 10;
	var xf = this.x + xdist;
	var yf = this.y + ydist;
	var num = Math.sqrt(Math.pow(xdist,2) + Math.pow(ydist,2))/inc;
	if (num==0) return;
	var dx = xdist/num;
	var dy = ydist/num;
	if (!f_funcion) f_funcion = null;
	this.arrastrando = true;
	this.arrastra( dx, dy, xf, yf, num, 1, velocidad, f_funcion );
}
function MundiCapaArrastra ( dx, dy, xf, yf, num, i, velocidad, f_funcion ) {
	if (i++ < num) {
		this.desplazaEn(dx,dy);
		setTimeout(this.obj+".arrastra("+dx+","+dy+","+xf+","+yf+","+num+","+i+","+velocidad+",\""+f_funcion+"\")",velocidad);
	}
	else {
		this.mueveA( xf, yf );
		this.arrastrando = false;
		eval( f_funcion );
	}
}
function MundiCapaClipInit(cT,cR,cB,cL) {
	if (ie4) {
		if (arguments.length==4) this.clipTo(cT,cR,cB,cL)
		else this.clipTo(0,this.w,this.h,0)
	}
}
function MundiCapaClipA(t,r,b,l) {
	if (ns4) {
		if (t!=null) this.estilo.clip.top = t;
		if (r!=null) this.estilo.clip.right = r;
		if (b!=null) this.estilo.clip.bottom = b;
		if (l!=null) this.estilo.clip.left = l;
	}
	else if (ie4) this.estilo.clip = "rect("+t+"px "+r+"px "+b+"px "+l+"px)";
	this.clipA_t = t;
	this.clipA_r = r;
	this.clipA_b = b;
	this.clipA_l = l;
}
function MundiCapaAgrandaEn (ydist, inc, velocidad, f_funcion) {
	if ( this.agrandando ) return
	if (!inc) inc = 10;
	if (!velocidad) velocidad = 10;
	ainc = (inc>0) ? inc : inc*(-1);
	var veces = ydist/ainc;
	this.agrandando = true;
	this.agranda(veces, inc, velocidad, f_funcion);
}
function MundiCapaAgranda (veces, inc, velocidad, f_funcion) {
 	if (veces>0) {
		this.clipA( 0,this.clipA_r,this.clipA_b+inc,0 );
 		veces--;
		setTimeout(this.obj+".agranda("+veces+","+inc+","+velocidad+",\""+f_funcion+"\")",velocidad);
 	} else {
 		this.agrandando = false;
		eval( f_funcion );
	}
}
