var containerWidth = 738;
var itemWidth = 150;
var offset = new Array();
var timeout = 20; //milliseconds
var sliderTimer;

function startSlider(num)
{
	var div = document.getElementById("scroll");

	for (var i = 0; i < num; i++)
	{
		var innerDiv = div.getElementsByTagName("div")[i];

		// init
		if (offset[i] == null)
		{
			offset[i] = itemWidth * i;
		}

		// start over
		if (offset[i] < -1 * itemWidth)
		{
			offset[i] = containerWidth ;
		}

		// get next div going
		if (Math.floor(containerWidth / itemWidth) > num)
		{
			if (offset[i - 1] == containerWidth - itemWidth - 2) // leave 2px of space between divisions
			{
				offset[i] = containerWidth;
			}
		}
		else
		{
			// last element entered carousel, first element re-set
			if (offset[i - 1] == null && offset[num - 1] > containerWidth - itemWidth - 2 && offset[0] == containerWidth)
			{
				offset[0] = containerWidth + 1;
			}
			else if (offset[i - 1] > containerWidth - itemWidth - 2 && offset[i] == containerWidth)
			{
				offset[i] = containerWidth + 1;
			}
		}
		innerDiv.style.display = "block";
			offset[i] = offset[i] - 1;  // meaning slider will go from left to right
		innerDiv.style.left = offset[i] + "px";
	}

	sliderTimer = setTimeout("startSlider(" + num + ")", timeout);
}
function holdScroll()
{
	clearTimeout(sliderTimer);
}
function continueScroll(num)
{
	sliderTimer = setTimeout("startSlider(" + num + ")", timeout);
}
