var enMovimiento = false;
var thumbnailSize = 48;
var totalWidth = 850;
var stepSize = 4;
var stepTimeout = 5;
var currentOffset = 0;

function dcha()
{
	if (!enMovimiento)
	{
		mueve_dcha();
	}
}

function mueve_dcha()
{
	var leftPos = parseInt(document.all.motiongallery.style.left);
	
	if (enMovimiento) 
	{
		if (currentOffset < thumbnailSize)
		{
			document.all.motiongallery.style.left = (leftPos - stepSize) + "px";
			currentOffset+=stepSize;
			setTimeout("mueve_dcha()", stepTimeout);
		
		}
		else
		{
			enMovimiento = false;
		}
	
	} 
	else 
	{
		if ( leftPos > (-1*totalWidth) ) {
			enMovimiento=true;
			document.all.motiongallery.style.left = (leftPos - stepSize) + "px";
			currentOffset=stepSize;
			setTimeout("mueve_dcha()", stepTimeout);
		}
	}
	
}

function izqda()
{
	if (!enMovimiento)
	{
		mueve_izqda();
	}
}

function mueve_izqda()
{
	var leftPos = parseInt(document.all.motiongallery.style.left);
	
	if (enMovimiento) 
	{
		if (currentOffset < thumbnailSize)
		{
			document.all.motiongallery.style.left = (leftPos + stepSize) + "px";
			currentOffset += stepSize;
			setTimeout("mueve_izqda()", stepTimeout);
		}
		else
		{
			enMovimiento = false;
		}
	} 
	else 
	{
		if (leftPos < 0 ) 
		{
			enMovimiento = true;
			document.all.motiongallery.style.left = (leftPos + stepSize) + "px";
			currentOffset = stepSize;
			setTimeout("mueve_izqda()", stepTimeout);
		}	
	}	
}

var thumbnailSizeLibros = 95;
var totalWidthLibros = 530;

function abajo()
{
	if (!enMovimiento)
	{
		mueve_abajo();
	}
}

function mueve_abajo()
{
	var topPos = parseInt(document.getElementById('motiongallery').style.top);
	
	if (enMovimiento) 
	{
		if (currentOffset < thumbnailSizeLibros)
		{
			document.getElementById('motiongallery').style.top = (topPos - stepSize) + "px";
			currentOffset += stepSize;
			setTimeout("mueve_abajo()", stepTimeout);
		
		}
		else
		{
			enMovimiento = false;
		}
	
	} 
	else 
	{
		if ( topPos > (-1 * totalWidthLibros) ) {
			enMovimiento=true;
			document.getElementById('motiongallery').style.top = (topPos - stepSize) + "px";
			currentOffset = stepSize;
			setTimeout("mueve_abajo()", stepTimeout);
		}
	}
	
}

function arriba()
{
	if (!enMovimiento)
	{
		mueve_arriba();
	}
}

function mueve_arriba()
{
	var topPos = parseInt(document.getElementById('motiongallery').style.top);
	
	if (enMovimiento) 
	{
		if (currentOffset < thumbnailSizeLibros)
		{
			document.getElementById('motiongallery').style.top = (topPos + stepSize) + "px";
			currentOffset += stepSize;
			setTimeout("mueve_arriba()", stepTimeout);
		}
		else
		{
			enMovimiento = false;
		}
	} 
	else 
	{
		if (topPos < 0 ) 
		{
			enMovimiento = true;
			document.getElementById('motiongallery').style.top = (topPos + stepSize) + "px";
			currentOffset = stepSize;
			setTimeout("mueve_arriba()", stepTimeout);
		}	
	}	
}
