window.onload = imageRotatorInit;

var intervalPhotos;
var photos;
var photoContainer;
var posTop = 0;
var posLeft = 0;

function imageRotatorInit()
{
	photos = document.getElementById('photoInner'); 
	photoContainer = document.getElementById('photosContainer'); 

	photos.position = "absolute";
	
	photoContainer.style.position = "relative"; 

	photoContainer.style.clip = "rect(0px 0px " + photoContainer.style.height + " " + photoContainer.style.width + ")"; 
	photoContainer.style.overflow = "hidden";

	
	
	var posParent = photoContainer.offsetParent;
	do 
	{
		posTop += posParent.offsetTop;
		posLeft += posParent.offsetLeft;
	}
	while (posParent = posParent.offsetParent)

	posLeft = photoContainer.offsetParent.offsetLeft  + "px";

	photos.style.left = posLeft;
}

function moveImages(position)
{
	if (intervalPhotos != null) { stopMoveImages(); }
	intervalPhotos = setInterval("moveInterval(" + position + ")", 10);
}

function stopMoveImages()
{
	clearInterval(intervalPhotos);
}

function moveInterval(position)
{
	var futurePosition = parseInt(photos.style.left) + position;
	
	var limitLeft = parseInt(posLeft);
	var limitRight = parseInt(posLeft) - parseInt(photos.style.width) + parseInt(photoContainer.style.width);
	
	if (limitLeft >= futurePosition && futurePosition >= limitRight)
	{
		photos.style.left = futurePosition + 'px';
	}
	else
	{
		stopMoveImages();
	}
}