/******** BEGIN GLOBAL VARIABLES ***************************/

//var defaultScrollSteps = 83;
var defaultScrollSteps = 10;
var defaultScrollDistance = 415;
var currentPosition;
var lockFlag = 0;
var divWidth = 0;
var currentPage = 1;
var numPages = 0;

/******** END GLOBAL VARIABLES ***************************/

function startApp()
{

	//document.getElementById('thumbnails').style.width="auto";
	//alert(document.getElementById('thumbnails').style.width);
	//alert(document.getElementById('thumbnails').offsetWidth);

	/*
	document.getElementById('thumbnails').innerHTML = document.getElementById('thumbnails_holder').innerHTML
	document.getElementById('thumbnails').style.width="auto";
	divWidth = document.getElementById('thumbnails').offsetWidth;
	*/

	numPages = Math.ceil(numEntries / 5);
	currentEntryPage = Math.ceil(currentEntryLocation / 5);
	//alert("numPages: " + numPages + "\ncurrentEntryLocation: " + currentEntryLocation + "\ncurrentEntryPage:" + currentEntryPage);
	slideThumbnails('right', currentEntryPage);

}

function slideThumbnails(whichDirection, whatPage)
{


var whereStart = (((currentPage * defaultScrollDistance) - defaultScrollDistance) * -1);
var whereStop = (((whatPage * defaultScrollDistance) - defaultScrollDistance) * -1);
//alert("whereStart: " + whereStart + "\nwhereStop: " + whereStop);

	if (!lockFlag)
	{

	//	if ((!((currentPage == 1) && (whichDirection == "left"))) || (!((currentPage == numPages) && (whichDirection == "right"))))

		if ((!((currentPage == 1) && (whichDirection == "left"))) && (!((currentPage == numPages) && (whichDirection == "right"))))
		{

			if (currentPage == 1)
			{
				document.getElementById('thumbnails').style.left = "0px";
			}

			moveIt(whichDirection, (defaultScrollDistance / defaultScrollSteps), whereStart, whereStop);

		}

	} // end if (!lockFlag)

}

function moveIt(whichDirection, howFar, whereStart, whereStop)
{

	lockFlag = 1;

//	alert("BEFORE\ncurrentPosition: " + currentPosition + "\nhowFar: " + howFar + "\ndocument.getElementById('thumbnails').style.left: " + document.getElementById('thumbnails').style.left);
	currentPosition = parseInt(document.getElementById('thumbnails').style.left.substring(0, document.getElementById('thumbnails').style.left.indexOf("px")));
//	alert("AFTER\ncurrentPosition: " + currentPosition + "\nhowFar: " + howFar + "\ndocument.getElementById('thumbnails').style.left: " + document.getElementById('thumbnails').style.left);

	switch (whichDirection)
	{
		case "left" :
			if ((currentPosition + howFar) > whereStop)
			{
				document.getElementById('thumbnails').style.left = whereStop + "px";
			//	alert("currentPosition: " + currentPosition + "\\ndocument.getElementById('thumbnails').style.left: " + document.getElementById('thumbnails').style.left);
				currentPage = Math.abs(whereStop / defaultScrollDistance) + 1;
				clearTimeout();
				lockFlag = 0;
				return;
			}
			var newPosition = parseInt(parseInt(currentPosition) + parseInt(howFar));
			break;
		case "right" :
			if ((currentPosition - howFar) < whereStop)
			{
				document.getElementById('thumbnails').style.left = whereStop + "px";
				currentPage = Math.abs(whereStop / defaultScrollDistance) + 1;
				clearTimeout();
				lockFlag = 0;
				return;
			}

			var newPosition = parseInt(parseInt(currentPosition) - parseInt(howFar));
			break;
	} // end switch (whichDirection)

	//alert("currentPosition: " + currentPosition + "\nnewPosition: " + newPosition);
	document.getElementById('thumbnails').style.left = newPosition + "px";

	var moveItString = "moveIt('" + whichDirection + "', '" + howFar + "', '" + whereStart + "', '" + whereStop + "');";
	setTimeout(moveItString, 1);

}