function Scroll(CapaContenedora,CapaDatos)
{
	this.CapaPrincipal=document.getElementById(CapaContenedora)
	this.CapaAMover=document.getElementById(CapaDatos)
	this.flechaArriba=null
	this.flechaAbajo=null
	this.flechaIzquierda=null
	this.flechaDerecha=null
	
	if(arguments.length>2)
	{
		this.flechaArriba=document.getElementById(arguments[2])
	}

	if(arguments.length>3)
	{
		this.flechaAbajo=document.getElementById(arguments[3])
	}	

	if(arguments.length>4)
	{
		this.flechaIzquierda=document.getElementById(arguments[4])
	}

	if(arguments.length>5)
	{
		this.flechaDerecha=document.getElementById(arguments[5])
	}	
	this.Inicializa=Inicializa
	this.InicializaFlechas=InicializaFlechas
	this.ParaScroll=ParaScroll
	this.MoverArriba=MoverArriba
	this.MoverAbajo=MoverAbajo
	this.MoverIzquierda=MoverIzquierda
	this.MoverDerecha=MoverDerecha
	this.ScrolearArriba=ScrolearArriba
	this.ScrolearAbajo=ScrolearAbajo
	this.ScrolearIzquierda=ScrolearIzquierda
	this.ScrolearDerecha=ScrolearDerecha
	this.Mover=Mover
	this.TransformaANumero=TransformaANumero
	this.Inicializa()
}

function Inicializa()
{
	this.CapaPrincipal.style.position="relative"
	this.CapaPrincipal.style.overflow="hidden"

	this.CapaAMover.style.position="absolute"
	this.CapaAMover.style.top=0
	this.CapaAMover.style.left=0
	
	this.RecorridoVertical=this.CapaAMover.offsetHeight-this.CapaPrincipal.offsetHeight
	this.RecorridoHorizontal=this.CapaAMover.offsetWidth-this.CapaPrincipal.offsetWidth
	if(this.flechaArriba!=null && this.flechaAbajo!=null)
	{
		visible=(this.RecorridoVertical>0)
		this.InicializaFlechas(this.flechaArriba,visible,this.ScrolearArriba)
		this.InicializaFlechas(this.flechaAbajo,visible,this.ScrolearAbajo)
	}
	
	this.loop=false
	this.Movimiento=5
	this.Velocidad=50
	this.Intervalo=null
    this.obj = "ObjectScroll"+Math.round(Math.random()*1234556789) 
    eval(this.obj + "=this") 
	this.Mover(0,0)

}

function InicializaFlechas(flecha,visible,funcion)
{
	tag=flecha.getElementsByTagName("A")[0]
	if(visible)
	{
		tag.onmouseup=this.ParaScroll
		tag.onmouseout=this.ParaScroll
		tag.onmousedown=funcion
		tag.objScroll=this
	}
	else
	{
		flecha.style.visibility="hidden"
		$('barraScroll').style.visibility="hidden";
		tag.onmouseup=null
		tag.onmouseout=null
		tag.onmousedown=null
		tag.objScroll=null
	}
}

function Mover(x,y)
{ 

	this.CapaAMover.style.top=y +"px";
    //this.CapaAMover.style.left=this.CapaAMover.style.left+"px"
    //this.CapaAMover.style.top=this.CapaAMover.style.top+"px"
} 

function ParaScroll()
{
	this.objScroll.loop=false
	window.clearTimeout(this.objScroll.Intervalo)
}

function MoverArriba()
{
	coorY=this.TransformaANumero(this.CapaAMover.style.top)
	coorX=this.TransformaANumero(this.CapaAMover.style.left)
	if(coorY<0)
	{
	   this.Mover(coorX,coorY+this.Movimiento) 
	   if(this.loop)
	   {
		   this.Intervalo=window.setTimeout(this.obj+".MoverArriba()",this.Velocidad) 
		}
	}
}

function MoverAbajo()
{
	coorY=this.TransformaANumero(this.CapaAMover.style.top)
	coorX=this.TransformaANumero(this.CapaAMover.style.left)
	if(coorY>(-this.RecorridoVertical))
	{
	   this.Mover(coorX,coorY-this.Movimiento) 
	   if(this.loop)
	   {
		   this.Intervalo=window.setTimeout(this.obj+".MoverAbajo()",this.Velocidad) 
		}
	}
}

function MoverIzquierda()
{
	coorY=this.TransformaANumero(this.CapaAMover.style.top)
	coorX=this.TransformaANumero(this.CapaAMover.style.left)
	if(coorX<0)
	{
	   this.Mover(coorX+this.Movimiento,coorY) 
	   if(this.loop)
	   {
		   this.Intervalo=window.setTimeout(this.obj+".MoverIzquierda()",this.Velocidad) 
		}
	}
}

function MoverDerecha()
{
	coorY=this.TransformaANumero(this.CapaAMover.style.top)
	coorX=this.TransformaANumero(this.CapaAMover.style.left)
	if(coorX>(-this.RecorridoHorizontal))
	{
	   this.Mover(coorX-this.Movimiento,coorY) 
	   if(this.loop)
	   {
		   this.Intervalo=window.setTimeout(this.obj+".MoverDerecha()",this.Velocidad) 
		}
	}

}

function ScrolearArriba()
{
	this.objScroll.loop=true
	this.objScroll.MoverArriba()
}

function ScrolearAbajo()
{
	this.objScroll.loop=true
	this.objScroll.MoverAbajo()
}

function ScrolearIzquierda()
{
	this.objScroll.loop=false
	this.objScroll.MoverIzquierda()
}

function ScrolearDerecha()
{
	this.objScroll.loop=false
	this.objScroll.MoverDerecha()
}

function TransformaANumero(coor)
{
	coor=coor.replace("px","")
	coor=coor.replace("pt","")
	num=new Number(coor)
	return(num)
}



