// JavaScript Document
var thescrollingdiv;
var currentLeftMarg;
var newMarg;
var width=600; // el ancho real se determina por el script en php
var movingrate=1;
var time=30;
var direction=-1; // left at start
var displaywidth=568;
var margins=45;

function scrollpublicidad(width){
	window.setInterval('scrollitonce('+ width +');', time);
}

function pausepublicidad (){
	movingrate=0;
}

function resumepublicidad (){
	movingrate=1;
}

function scrollitonce(width){
	// desplazar el div de las publicidades de manera que siempre se vean todos
	// alert('ok');
	thescrollingdiv=document.getElementById('thumbscroller');
	//get the current left margin integer
	var currentLeftMarg = parseInt(thescrollingdiv.style.marginLeft);
	// var currentRightMarg = parseInt(thescrollingdiv.style.marginRight);


	if (isNaN(currentLeftMarg)) {
		// alert('Please enter only numerical values into Field 1.');
		currentLeftMarg = margins;
	}
	
	// var newMarg = (currentLeftMarg > (width*-1)) ? currentLeftMarg - movingrate : currentLeftMarg + movingrate ;
	// currentLeftMarg = currentLeftMarg 

	if (currentLeftMarg > ((margins + width) *-1) + displaywidth  && direction==-1)  {
		var newMarg = currentLeftMarg - movingrate ;
	} else {
		var newMarg = currentLeftMarg + movingrate ;
		direction = 1;
	}
	if (currentLeftMarg > margins) direction = -1;
	
	//now set the new margin
	
	if (movingrate!=0) 
	thescrollingdiv.style.marginLeft = newMarg + "px";
	
	// alert(newMarg);
	// alert(currentLeftMarg);
	
	// alert(parseInt(currentLeftMarg));
	// thescrollingdiv.scrollTop =(thescrollingdiv.scrollTop-10);
	

}