// teknoClip 1.0 - Object Development by Teknoland RTT
// Real Time Team, 2000 alex
//
// ----------------------- Constructor -------------------------
//   teknoClip(obj,capa) 
//     obj = nombre de la instancia del objeto a crear 
//     capa = nombre de la capa a inicializar
//
// --------------------- Propiedades -----------------------
//	  name -> nombre de la capa a inicializar
//	  nameObj -> nombre de la instancia del objeto
//   ancho -> ancho de la capa
//   alto -> alto de la capa
//
// ----------------------- Métodos -------------------------
//   reset() -> Hacer un reset de la capa y dejarla con su tamaño original
//   clipRH(x,y) -> Hacer clip de la capa hacia la derecha ocultando la capa
//   clipRV(x,y) -> Hacer clip de la capa hacia la derecha poniendo visible la capa
//   clipLH(x,y) -> Hacer clip de la capa hacia la izquierda ocultando la capa
//   clipLV(x,y) -> Hacer clip de la capa hacia la izquierda poniendo visible la capa
//   clipTH(x,y) -> Hacer clip de la capa hacia arriba ocultando la capa
//   clipTV(x,y) -> Hacer clip de la capa hacia arriba poniendo visible la capa
//   clipBH(x,y) -> Hacer clip de la capa hacia abajo ocultando la capa
//   clipBV(x,y) -> Hacer clip de la capa hacia abajo poniendo visible la capa
//							En todos estos métodos hay que pasar dos parámetros:
//							x: resolución del clip
//							y: velocidad del clip//
//   visible() -> Hacer visible la capa
//   hide() -> Ocultar la capa
//   klip(a,b,c,d) -> Hace un clip homogéneo para los 2 navegadores, hay que pasarle 4 parámetros:
//							a: nº de pixels que corto desde arriba
//							b: nº de pixels que dejo ver de izquierda a derecha
//							c: nº de pixels que dejo ver arriba a abajo
//							d: nº de pixels que corto desde la izquierda

function Clip(obj,capa){

	//variables auxiliares
	this.IE4 = (document.all) ? 1 : 0;
	this.NN4 = (document.layers) ? 1 : 0;
	this.doc = (this.IE4) ? "document.all." : "document.";
	this.stl = (this.IE4) ? ".style." : ".";
	this.topp = (this.IE4) ? "pixelTop" : "top";
	this.leff = (this.IE4) ? "pixelLeft" : "left";
	this.widz = (this.IE4) ? "pixelWidth" : "clip.width";
	this.heiz = (this.IE4) ? "pixelHeight" : "clip.height";
	this.tmr = 0;

	// propiedades
	this.nameObj = obj;
	this.name = capa;
	eval("this.ancho = " + this.doc + this.name + this.stl + this.widz);
	eval("this.alto = " + this.doc + this.name + this.stl + this.heiz);
	this.cTop = 0;
	this.cRight = this.ancho;
	this.cBottom = this.alto;
	this.cLeft = 0;

	// métodos
	this.reset = reset;
	this.clipRH = clipRH;
	this.clipRV = clipRV;
	this.clipLH = clipLH;
	this.clipLV = clipLV;
	this.clipTH = clipTH;
	this.clipTV = clipTV;
	this.clipBH = clipBH;
	this.clipBV = clipBV;
	this.visible = visible;
	this.hide = hide;
	this.klip = klip;	

	this.klip(0,this.ancho,this.alto,0);
}

function reset(){
	this.klip(0,this.ancho,this.alto,0);
	clearTimeout(this.tmr);
	this.cTop = 0;
	this.cRight = this.ancho;
	this.cBottom = this.alto;
	this.cLeft = 0;
}

function clipRH(res,vel){
	this.klip(0,this.ancho,this.alto,this.cLeft);
	if(this.cLeft<this.ancho){
		this.cLeft+=res;
		this.tmr = setTimeout(this.nameObj + '.clipRH('+res+','+vel+')',vel);
	}
	else{
		clearTimeout(this.tmr);
		this.cLeft = 0;
	}
}

function clipRV(res,vel){
	this.klip(0,this.cLeft,this.alto,0);
	if(this.cLeft<this.ancho){
		this.cLeft+=res;
		this.tmr = setTimeout(this.nameObj + '.clipRV('+res+','+vel+')',vel);
	}
	else{
		clearTimeout(this.tmr);
		this.cLeft = 0;
	}
}

function clipLH(res,vel){
	this.klip(0,this.cRight,this.alto,0);
	if(this.cRight>0){
		this.cRight-=res;
		this.tmr = setTimeout(this.nameObj + '.clipLH('+res+','+vel+')',vel);
	}
	else{
		clearTimeout(this.tmr);
		this.cRight = this.ancho;
	}
}

function clipLV(res,vel){
	this.klip(0,this.ancho,this.alto,this.cRight);
	if(this.cRight>0){
		this.cRight-=res;
		this.tmr = setTimeout(this.nameObj + '.clipLV('+res+','+vel+')',vel);
	}
	else{
		clearTimeout(this.tmr);
		this.cRight = this.ancho;
	}
}

function clipTH(res,vel){
	this.klip(0,this.ancho,this.cBottom,0);
	if(this.cBottom>0){
		this.cBottom-=res;
		this.tmr = setTimeout(this.nameObj + '.clipTH('+res+','+vel+')',vel);
	}
	else{
		clearTimeout(this.tmr);
		this.cBottom = this.alto;
	}
}

function clipTV(res,vel){
	this.klip(this.cBottom,this.ancho,this.alto,0);
	if(this.cBottom>0){
		this.cBottom-=res;
		this.tmr = setTimeout(this.nameObj + '.clipTV('+res+','+vel+')',vel);
	}
	else{
		clearTimeout(this.tmr);
		this.cBottom = this.alto;
	}
}

function clipBH(res,vel){
	this.klip(this.cTop,this.ancho,this.alto,0);
	if(this.cTop<this.alto){
		this.cTop+=res;
		this.tmr = setTimeout(this.nameObj + '.clipBH('+res+','+vel+')',vel);
	}
	else{
		clearTimeout(this.tmr);
		this.cTop = 0;
	}
}

function clipBV(res,vel){
	this.klip(0,this.ancho,this.cTop,0);
	if(this.cTop<this.alto){
		this.cTop+=res;
		this.tmr = setTimeout(this.nameObj + '.clipBV('+res+','+vel+')',vel);
	}
	else{
		clearTimeout(this.tmr);
		this.cTop = 0;
	}
}

function visible(){
	eval(this.doc + this.name + this.stl + "visibility='visible'");
}

function hide(){
	eval(this.doc + this.name + this.stl + "visibility='hidden'");
}

function klip(a,b,c,d){
	if (this.IE4){
		eval(this.doc + this.name + this.stl + "clip='rect('+a+','+b+','+c+','+d+')'");
	}
	else{
		eval(this.doc + this.name + ".clip.top=" + a);
		eval(this.doc + this.name + ".clip.right=" + b);
		eval(this.doc + this.name + ".clip.bottom=" + c);
		eval(this.doc + this.name + ".clip.left=" + d);
	}
}
