var offset = 0;

function boundsCheck(offset)
{
	//do a left bounds check
	var viewport = document.getElementById("viewPort");
	var scrolldiv = document.getElementById("scrollContent");
	var styleLeft = getScrollLeftValue();
	// check if the content has been scrolled as far left as it can go
	if((styleLeft * -1) >= (scrolldiv.clientWidth - viewport.clientWidth))
	{
		// if so, kill the scrolling if they're trying to scroll left
		if(offset < 0) return 0;
	}
	// do a right bounds check
	// check if the content has been scrolled right as far as it can go
	if(styleLeft >= 0)
	{
		// if so kill the scrolling if they're still trying to scroll right
		if(offset > 0) return 0;
	}
	return offset;
}

function scroll()
{
	offset = boundsCheck(offset);
	if(offset == 0) return;
	// still scrolling and not out of bounds, let's go
	var styleLeft = getScrollLeftValue();
	// alter it
	styleLeft = styleLeft + offset;
	// set it again
	var content = document.getElementById("scrollContent");
	content.style.left = styleLeft + "px";
	// and call ourselves again
	var timer = setTimeout("scroll()",100);
}

function getScrollLeftValue()
{
	// get the scroll content elemnent
	var content = document.getElementById("scrollContent");
	// grab the left value
	var leftvalue = content.offsetLeft;
	// return it
	return leftvalue;
}

function startScrolling(newOffset)
{
	// set up the offset value
	offset = newOffset;
	// start scrolling
	scroll();
}

function stopScrolling()
{
	// set the offset to 0, scroll will stop itself next time it's called
	offset = 0;
}

function flip(imgsource,imgdest)
{
	// grab the src from the source and set it to the dest
	var source = document.getElementById(imgsource);
	var dest = document.getElementById(imgdest);
	source.src = dest.src;
}
