
//************************************
// Objeto Capa
//************************************


function Capa(nombre,px,py,pw,ph,cl,ct,cr,cb,visible)
{
this.nombre = nombre;

 IniciaCapa(nombre, px, py, pw, ph, cl, ct, cr, cb, visible)

 this.mover = mover;
 this.posicionar = posicionar;
 this.setVisible = setVisible;
 this.isVisible = isVisible;
 this.getX = getX;
 this.getY = getY;
 this.setX = getX;
 this.setY = getY;
 this.getWidth = getWidth;
 this.getHeight = getHeight;
 this.setWidth = setWidth;
 this.setHeight = setHeight;
 this.redim = redim;
 this.getClip = getClip;
 this.setClip = setClip;

 this.numAnim=-1;
 this.tamanioInicial = new Clip(this.getX(),this.getY(),this.getWidth(),this.getHeight())


 this.animandose = CAanimandose;
 this.animar = animar;
 this.aparicionSimple = CAaparicionSimple;
 this.aparicion = aparicion;
 this.cancelarAnimacion = CAcancelarAnimacion;
 this.guardarDimensiones = CAguardarDimensiones;
 this.modificar = CAmodificar
 

 this.isCompleto = CAisCompleto;
 this.restaurarCapa = CArestaurarCapa;


}

function CArestaurarCapa()
{
	var	tam = this.tamanioInicial ;
	this.posicionar(tam.x1,tam.y1);
	this.setClip(new Clip(0,0,tam.x2,tam.y2));
}

function CAanimandose()
{

	var tam = this.tamanioInicial;
	
	//if ( (this.getX()==tam.x1 && this.getY() == tam.y1 ))
	if ( (this.getX()==tam.x1 && this.getY() == tam.y1 ) ||
	     (this.getX()==tam.x1 - tam.x2) || (this.getX()==tam.x1 + tam.x2) ||
		 (this.getY()==tam.y1 - tam.y2) || (this.getY()==tam.y1 + tam.y2) )
	
	{
	
		return false;
	}
	else return true;

}

function mover(dx,dy)
{
	DesplazaCapa(this.nombre, parseInt(dx), parseInt(dy));
	this.guardarDimensiones();
}

function posicionar(px, py)
{	

	PosicionaCapa(this.nombre, parseInt(px), parseInt(py));
	this.guardarDimensiones();
}

function setVisible(visible)
{
	if (visible)
	{
		MuestraCapa(this.nombre);
	}
	else 
	{
		OcultaCapa(this.nombre);
	}

}

function isVisible()
{
	return EsVisible(this.nombre);
}

function getX()
{
	return CapaX(this.nombre);
}

function getY()
{
	return CapaY(this.nombre);
}

function setX(x)
{
	PosicionaCapaX(this.nombre,x);
	this.guardarDimensiones();
}

function setY(y)
{
	PosicionaCapaY(this.nombre,y);
	this.guardarDimensiones();
}


function getWidth()
{
	return CapaAncho(this.nombre);
}

function getHeight()
{
	return CapaAlto(this.nombre);
}

function setWidth(w)
{
	DimensionaCapa(this.nombre, w, this.getHeight());
	this.guardarDimensiones();
}

function setHeight(h)
{
	DimensionaCapa(this.nombre, this.getWidth(), h);
	this.guardarDimensiones();
}

function redim(w,h)
{
	DimensionaCapa(this.nombre,w,h);
	this.guardarDimensiones();
}

function setClip(clip)
{
	RecortaCapa(this.nombre, clip.x1, clip.y1, clip.x2,clip.y2) ;

}

function getClip()
{
	return new Clip(CapaClipX1(this.nombre),CapaClipY1(this.nombre),CapaClipX2(this.nombre),CapaClipY2(this.nombre));
}

function animar( x, y, tiempo, flags, funfin, relativa)
{

		
	if (relativa)
	{
		this.numAnim = AnimacionCapaRelativa(this.nombre, x, y, tiempo, flags, funfin);
	}
	else 
	{
		this.numAnim = AnimacionCapa(this.nombre, x, y, tiempo, flags, funfin);
	}
	
}




function CAaparicionSimple(lado,direccion,milisegundos)
{
	

	if (direccion=="al")
	{
		this.setVisible(true);
		this.aparicion(lado,direccion,milisegundos,false,true,false);
	}
	else 
	{
		this.aparicion(lado,direccion,milisegundos,false,true,true);
	}

}

function aparicion(lado,direccion,milisegundos,mostrarAlFinal,cancelar,ocultarAlFinal)
{

	//lado = n->norte,s->sur,e->este,o->oeste
	//direccion = al->alante at->atras

	
	if (cancelar!=null && cancelar==true)
	{
		this.cancelarAnimacion()
	}
	
	var funcion = "";
	if (mostrarAlFinal!=null)
	{
		if (mostrarAlFinal) funcion = "MuestraCapa('" + this.nombre + "');";
	}
	
	if (ocultarAlFinal!=null)
	{
		if (ocultarAlFinal) funcion = "OcultaCapa('" + this.nombre + "');";
	}


	var ti = this.tamanioInicial
	var movX,movY;
	var tiempo,porc,dif;
	var clip;
		
	if (lado=="n")
	{		
		clip="tb";
		movX=0;
		
		if (direccion=="at") movY= parseInt(ti.y1- this.getHeight() - this.getY());
		if (direccion=="al") movY= parseInt(ti.y1 - this.getY());
	}
	
	if (lado=="s")
	{
		clip="tb";
		movX=0;
		
		if (direccion=="at") movY= parseInt(this.getHeight() - (this.getY()-ti.y1));
		if (direccion=="al") movY= parseInt(ti.y1 - this.getY());
	}

	if (lado=="e")
	{
		clip="lr";
		movY=0;
		
		if (direccion=="at") movX= parseInt(this.getWidth() - (this.getX()-ti.x1));
		if (direccion=="al") movX= parseInt(ti.x1 - this.getX());

	}
	
	if (lado=="o")
	{
		clip="lr";
		movY=0;
		
		if (direccion=="at") movX= parseInt(ti.x1 -this.getWidth() - this.getX());
		if (direccion=="al") movX= parseInt(ti.x1 - this.getX());
		
	}
	

	if (movX==0 && movY==0) return;
	

	porc = ((Math.abs(movX)+Math.abs(movY)) / this.getHeight());
	tiempo = parseInt(milisegundos * porc);

	//alert ("movX=" + movX + "\n movY="+ movY+ "\n tiempo=" + tiempo + "\n clip=" + clip)
	
	this.animar( movX, movY, tiempo, clip,funcion,true);
	

}


function CAcancelarAnimacion()
{
	
	
	if (this.animandose())
	{
	CancelaAnimacion(this.numAnim);
	}

	
}

function CAguardarDimensiones()
{
	this.tamanioInicial = new Clip(this.getX(),this.getY(),this.getWidth(),this.getHeight())
}

function CAisCompleto()
{
	//nos dice si se esta mostrando entero
	ti  = this.tamanioInicial
	return (ti.x1 == this.getX() && ti.y1 == this.getY());
}

function CAmodificar(texto)
{

  if (document.getElementById && !document.all)
  { //N6 
	document.getElementById(this.nombre).innerHTML=texto;
	return
  }


  if(document.layers)
  { 
    //N4;
    document.layers[this.nombre].document.open();
    document.layers[this.nombre].document.write(texto);
	document.layers[this.nombre].document.close();
    
  }
  else 
  { 
    //Exporer 
	document.all[this.nombre].innerHTML=texto;  
  }

}


//****************************************
//fin objeto capa
//****************************************



//************************************
// Objeto Clip
//************************************

function Clip(x1,y1,x2,y2)
{

	this.x1=x1;
	this.y1=y1;
	this.x2=x2;
	this.y2=y2;
	
	
}

//****************************************
//fin objeto Clip
//****************************************


