
var theScroll;
var timer;
var cont =0;
//var delay = 50;
var delay = 50;

function parar(){
	clearTimeout(timer);
}


function moveDiv () {
	
	timer = window.setTimeout ( this.gRef+".moveDiv()" , delay );
	
    lyrId1 =this.id +"Contedor";	
	lyrId2 =this.id +"Contido";
	//var out = document.getElementById("out");
	var d = document;	
	var px =0;
	var npxls =2;
	//alert("Hello!!");
	this.container = this.y.dom ? d.getElementById(lyrId1) : this.y.ie ? d.all[lyrId1] : d.layers[lyrId1];
	this.content = obj2 = this.y.ns4 ? this.container.layers[lyrId2] : this.y.ie ? d.all[lyrId2] : d.getElementById(lyrId2);
	
    //var div = d.getElementById(lyrId2);
	this.docH = Math.max(this.y.ns4 ? this.content.document.height : this.content.offsetHeight, this.clipH);
	this.docW = Math.max(this.y.ns4 ? this.content.document.width : this.content.offsetWidth, this.clipW);
	this.scrollH = this.docH - this.clipH
	this.scrollW = this.docW - this.clipW;
	
	if(this.mov == 0 ){	
	//Scroll izq ---> dch
		if ( !this.content.style.left) { this.content.style.left = ( parseInt( -this.docW )  )+ "px"; }
		if( parseInt(this.content.style.left)  <=  ( this.width)  ){		
	    px = parseInt(this.content.style.left);
		px = px+npxls;
		this.content.style.left=parseInt(px)+"px";		
		}else{
			this.content.style.left =(parseInt( -this.docW ) )+ "px";		
		}
	}
	if(this.mov == 1 ){
	//Scroll izq <--- dch
		if ( !this.content.style.left) { this.content.style.left = ( parseInt(  this.width )  )+ "px"; }
		if( parseInt(this.content.style.left)  >=  parseInt( -this.docW )  ){		
	    	px = parseInt(this.content.style.left);
			px=px-npxls;
		this.content.style.left=parseInt(px)+"px";		
	}else{

		this.content.style.left =(parseInt( this.width ) )+ "px";		
		}	
	}
	if( this.mov == 2){
	//Scroll de abaixo arriba
	if ( !this.content.style.top) { this.content.style.top = ( parseInt(  this.height )  )+ "px"; }
		//out.innerHTML ="height do contido: "+ this.docH+" Height do contedor: "+this.height+" Posicion top: "+this.content.style.top;
		if( parseInt(this.content.style.top)  >=  ( parseInt(- this.docH ) )  ){		
	    px = parseInt(this.content.style.top);
		//px = px-1;
		px = px-36;
		this.content.style.top=parseInt(px)+"px";		
		}else{
			this.content.style.top =( parseInt(  this.height )  )+ "px";		
		}		
		
	}
	if( this.mov == 3){
	//Scroll de arriba abaixo
	if ( !this.content.style.top) { this.content.style.top = ( parseInt(  -this.docH )  )+ "px"; }
		//out.innerHTML ="height do contido: "+ this.docH+" Height do contedor: "+this.height+" Posicion top: "+this.content.style.top;
		if( parseInt(this.content.style.top)  <=  ( parseInt( this.height  ) )  ){		
	    px = parseInt(this.content.style.top);
		px = px+1;
		this.content.style.top=parseInt(px)+"px";		
		}else{
			this.content.style.top =( parseInt(  -this.docH   )  )+ "px";		
		}		
		
	}	
						
}

objScroll.minRes = 10
objScroll.ie = document.all ? 1 : 0
objScroll.ns4 = document.layers ? 1 : 0
objScroll.dom = document.getElementById ? 1 : 0
objScroll.mac = navigator.platform == "MacPPC"
objScroll.mo5 = document.getElementById && !document.all ? 1 : 0

/* 
	Parámetros do constructor do scroll:
	id -->  nome parcial das capas que conteñen o scroll
	left--> posicion a esquerda (relativia ó contenedor)
	left--> posicion en altura  (relativia ó contenedor)
	width--> ancho (horizontal)
	height-->ancho vertical
	mov --> inidcador do tipo de movemento:
					- 0: horizontal de esquerda a dereita 
					- 1: horizontal de dereita a esquerde
					- 2: vertical de abaixo arriba
					- 3: vertical de arriba abaixo
*/

function objScroll(id, left, top, width, height, mov){
//alert("constructor");
var y = this.y = objScroll;
if (document.layers && !y.ns4) history.go(0)
	if (y.ie || y.ns4 || y.dom) {	
	this.mov = mov;
	this.id = id;
	this.left = left;
	this.top = top;
	this.startLeft = 0;
	this.startTop = 0;
	this.clipH = height;
	this.clipW = width;
	this.scrollTop = 0;
	this.scrollLeft = 0;
	this.moveDiv = moveDiv;
	this.width = width;
	this.height = height;
	this.gRef = "objScroll_"+id
	eval(this.gRef+"=this")
//clip:rect( 0, '+this.width+'px, '+this.height+'px, ' +'0 );
style ='<style type="text/css">';
	style += '#'+id+'Contedor{ position:relative; overflow:hidden;left:'+this.left+'px; top:'+this.top+'px; width:+'+width+'px;height:'+height+'px;clear:both; clip:rect( 0, '+this.width+'px, '+this.height+'px, ' +'0 );} '
	//style += '#'+id+'Contido{ left:' + (-this.scrollLeft) + 'px; top:' + (-this.scrollTop) + 'px; }';
	style += '#'+id+'Contido{ text-align:left; white-space:nowrap;position:absolute;left:' + (-this.scrollLeft) + 'px; top:' + (-this.scrollTop) + 'px; }'
	style += '</style>';
	document.write(style);
} 
}

function instanciaScroll(id, left, top, width, height, mov){	
	theScroll = new objScroll(id,left, top, width, height, mov);	
} 

//inicializacion
function initOnLoad( fn ){
	var old = window.onload;
	//alert("init OnLoad, old: "+old);
	//fn();	
	if (typeof window.onload != 'function') {				
		window.onload = fn;		 
      }
	  else{
	  	window.onload = function(){		
			old();
			fn();
		}
	  }
}

initOnLoad( function(){ //Con isto engadiremos os eventos
	//var hmtl = "<span>cargado dende initOnLoad (sobreescribe onload)</span>";
	//var div = document.getElementById("kk");
	//div.innerHTML =  hmtl;    
	theScroll.moveDiv();
	
}
)
function move(){
	theScroll.moveDiv();
}

