//Code by Jorge Arevalo (quorthon@mailcity.com)
//------------------------------------------------
//Widget based upon the tutorials an libraries by
// Copyright (C) 1999 Dan Steinman ,Distributed under the terms of the GNU Library General Public License Available at http://www.dansteinman.com/dynapi/

function scroller(nombre,velocidad,velocidadrepeticion,direccion,rotativa,margen)  
{
 this.nombre = nombre    				        //en cadena de texto, por si es necesario
 this.contenedor = eval(nombre+"cont");   	//capa contenedor
 this.contenido1 = eval(nombre);          	//capa que esta contenida
 this.x = this.contenido1.x;
 this.y = this.contenido1.y;
 this.w = this.contenido1.getContentWidth();
 this.h = this.contenido1.getContentHeight();
 this.velocidadrepeticion=velocidadrepeticion;

 this.activo=0
 this.estado=0                               //contiene estado del escrolling, la variable 1 para mas, -1 para menos
 if (velocidad != null) this.velocidad = 5   //contiene aumentos por paso
 else this.velocidad = velocidad
 if (direccion != null) this.direccion = direccion //direccion de scroll, por defecto vertical 
 else this.direccion = "x"

 this.activar  = activar
 this.roll = roll
 this.desactivar  = desactivar
 this.salta = salta
 if (rotativa=="y")
 {
  this.rotativa="y"; 
  this.contenido2=eval(nombre+"2");  
  this.margen = margen      
  this.mostrada=1;
  if (direccion=="y") {xx=this.x; yy=this.h+this.margen;} else {xx=this.w+this.margen; yy=this.y;}
  this.contenido2.moveTo(xx,yy);
 }
}

function activar(){ this.contenido1.moveTo(0,0); this.x=0; this.y=0; this.activo=1; this.roll();  this.w = this.contenido1.getContentWidth(); this.h = this.contenido1.getContentHeight();}

function roll()
{
if (this.activo==1)
 {
  if (this.estado!=0) 
     {
	   vel = this.velocidad * this.estado; //preparamos velocidad
  	   if (this.direccion=="x")  		   //movimiento horizontal
	      { 
 		   if (this.rotativa!="y") 
		   		{
			   if (((this.x<0)&&(this.estado>0))||((this.x>=(this.w*-1)+40))&&(this.estado<0)) {this.contenido1.moveBy(vel,null);  this.x=this.contenido1.x;  }
				}
				else
				{
  				 this.contenido1.moveBy(vel,null); this.contenido2.moveBy(vel,null); 
				 if (vel>0)
				 { 
				   if (this.contenido1.x>this.w)  {this.contenido1.moveTo(this.w*-1-this.margen,null); }
				   else if (this.contenido2.x>this.w) {this.contenido2.moveTo(this.w*-1-this.margen,null); }				 
				 } 
 				else
				{
				   if ((this.contenido1.x<10)&&(this.contenido1.x>=0))  {this.contenido2.moveTo(this.w+this.margen,null); }
				   else if ((this.contenido2.x<10)&&(this.contenido2.x>=0)) {this.contenido1.moveTo(this.w+this.margen,null); }				 				
				}
 			}
		  }
       else    //movimiento Vertical
	      {  
		   if (this.rotativa!="y")
		   {		  
		    if (((this.y<0)&&(this.estado>0))||((this.y>=(this.h*-1)+40))&&(this.estado<0)) {this.contenido1.moveBy(null,vel);  this.y=this.contenido1.y;  }		    
		   }
			else
				{
  				 this.contenido1.moveBy(null,vel); this.contenido2.moveBy(null,vel); 
				 if (vel>0)
				 { 
				   if (this.contenido1.y>this.h)  {this.contenido1.moveTo(null,this.h*-1-this.margen); }
				   else if (this.contenido2.y>this.h) {this.contenido2.moveTo(null,this.h*-1-this.margen); }				 
				 } 
 				else
				{
				   if ((this.contenido1.y<10)&&(this.contenido1.y>=0))  {this.contenido2.moveTo(null,this.h+this.margen); }
				   else if ((this.contenido2.y<10)&&(this.contenido2.y>=0)) {this.contenido1.moveTo(null,this.h+this.margen); }				 				
				}
 			}		   
		   
		  }	 
     }
  aux=this.nombre+"scr";
  setTimeout(aux+".roll()",this.velocidadrepeticion);
 }
}

function desactivar(){ this.activo=0}
function salta(where)
{ 
if (this.activo==1)
   {
    if (where==0) {this.contenido1.glideTo("fast","slow",0,0,5,10); }
    else { if(this.direccion=="x") {this.contenido1.glideTo("fast","slow",this.w*-1+40,null,5,10); } else {this.contenido1.glideTo("fast","slow",null,this.h*-1+40,5,10); } }
	this.x=this.contenido1.x; this.y=this.contenido1.y;
   }	
}

//funciones de rotatorio