var CapasMover=new Array(),X0s=new Array(),Y0s=new Array(),X1s=new Array(),Y1s=new Array();
var DirecX=new Array(),Desps=new Array(),NumCapas;

//Argumentos:Id capa,Xfin,Yfin,Desplazamiento
function Mover()
{
 var args=Mover.arguments,Ind=0,Capa,XFin,YFin,Desp;

 NumCapas=args.length/4;

 for(i=0;i<args.length;i+=4)
 {
	XFin=X1s[Ind]=args[i+1];
	YFin=Y1s[Ind]=args[i+2];
	Desp=args[i+3];

	if(navigator.appName=='Netscape')
	{
	 CapasMover[Ind]=Capa=document.layers[args[i]];
	 if(Capa!=null)
	 {
		X0s[Ind]=Capa.left;
		Y0s[Ind]=Capa.top;

		if(Math.abs(Capa.left-XFin) >= Math.abs(Capa.top-YFin)) DirecX[Ind]=true;
		else  DirecX[Ind]=false;

		if(DirecX[Ind] && (Capa.left>XFin)) Desp=Desp*-1;
		else if(!DirecX[Ind] && Capa.top>YFin) Desp=Desp*-1;
	 }
	}
  	else //IE
  	{
	 CapasMover[Ind]=Capa=document.all[args[i]];
	 if(Capa!=null)
	 {
		X0s[Ind]=Capa.style.posLeft;
		Y0s[Ind]=Capa.style.posTop;

		if(Math.abs(Capa.style.posLeft-XFin) >= Math.abs(Capa.style.posTop-YFin)) DirecX[Ind]=true;
		else  DirecX[Ind]=false;

		if(DirecX[Ind] && (Capa.style.posLeft>XFin)) Desp=Desp*-1;
		else if(!DirecX[Ind] && Capa.style.posTop>YFin) Desp=Desp*-1;
	 }
	}
	Desps[Ind]=Desp;
	Ind++;
 }
 MoverCapas();
}

function MoverCapas()
{
 var Capa,X0,Y0,X1,Y1,PosX,PosY,Desp,Seguir=false;

 for(i=0;i<NumCapas;i++)
 {
	Capa=CapasMover[i];
	Desp=Desps[i];
	X0=X0s[i];
	Y0=Y0s[i];
	X1=X1s[i];
	Y1=Y1s[i];

	if(document.layers)	//NT
	{
	 if(Capa.left!=X1 || Capa.top!=Y1)
	 {
		Seguir=true;
		if(X0==X1)
		{
		 PosX=X1;
		 PosY=Capa.top+Desp;
		 if((Desp<0 && PosY<Y1) || (Desp>0 && PosY>Y1))	PosY=Y1;
		}
		else
		{
		 if(Y0==Y1)
		 {
			PosX=Capa.left+Desp;
			PosY=Y1;
			if((Desp<0 && PosX<X1) || (Desp>0 && PosX>X1))	PosX=X1;
		 }
		 else
		 {
			if(DirecX[i])
			{
			 PosX=Capa.left+Desp;
			 PosY=Math.round(((PosX-X0)*(Y1-Y0))/(X1-X0))+Y0;
			 if((Desp<0 && PosX<X1) || (Desp>0 && PosX>X1))
			 {
				PosX=X1;
				PosY=Y1;
			 }
			}
			else
			{
			 PosY=Capa.top+Desp;
			 PosX=Math.round(((PosY-Y0)*(X1-X0))/(Y1-Y0))+X0;
			 if((Desp<0 && PosY<Y1) || (Desp>0 && PosY>Y1))
			 {
				PosX=X1;
				PosY=Y1;
			 }
			}
		 }
		}
		Capa.left=PosX;
		Capa.top=PosY;
	 }
	}
	else	//IE
	{
	 if(Capa.style.posLeft!=X1 || Capa.style.posTop!=Y1)
	 {
		Seguir=true;
		if(X0==X1)
		{
		 PosX=X1;
		 PosY=Capa.style.posTop+Desp;
		 if((Desp<0 && PosY<Y1) || (Desp>0 && PosY>Y1))	PosY=Y1;
		}
		else
		{
		 if(Y0==Y1)
		 {
			PosX=Capa.style.posLeft+Desp;
			PosY=Y1;
			if((Desp<0 && PosX<X1) || (Desp>0 && PosX>X1))	PosX=X1;
		 }
		 else
		 {
			if(DirecX[i])
			{
			 PosX=Capa.style.posLeft+Desp;
			 PosY=Math.round(((PosX-X0)*(Y1-Y0))/(X1-X0))+Y0;
			 if((Desp<0 && PosX<X1) || (Desp>0 && PosX>X1))
			 {
				PosX=X1;
				PosY=Y1;
			 }
			}
			else
			{
			 PosY=Capa.style.posTop+Desp;
			 PosX=Math.round(((PosY-Y0)*(X1-X0))/(Y1-Y0))+X0;
			 if((Desp<0 && PosY<Y1) || (Desp>0 && PosY>Y1))
			 {
				PosX=X1;
				PosY=Y1;
			 }
			}
		 }
		}
		Capa.style.posLeft=PosX;
		Capa.style.posTop=PosY;
	 }
	}
 }
 if(Seguir) setTimeout("MoverCapas()",100);
}
