var intervalSleep = 30;
var totalIntervals = 25;

function scrollToFirstPage()
{
	return scrollToPage("firstPage");
}

function scrollToPage(pageName)
{
	stopScrolling();

	animation.intervalCount = 0;
	animation.beginPosition = document.getElementById("dbScrollArea").scrollLeft;
	animation.endPosition = document.getElementById(pageName).offsetLeft - document.getElementById("firstPage").offsetLeft;
	
	animation.timer = setInterval("scrollHorizAnimated();", intervalSleep);

	return false;
}

function stopScrolling()
{
	if (animation.timer != null)
	{
		clearInterval(animation.timer);
	
		animation.timer = null;
	}
}

var animation = { intervalCount:0, beginPosition:0, endPosition:0, timer:null };

function scrollHorizAnimated()
{
	if (animation.intervalCount > totalIntervals)
	{
		stopScrolling();
	}
	else 
	{
		change = (animation.endPosition - animation.beginPosition) * (Math.cos(Math.PI * animation.intervalCount / totalIntervals) - 1) / 2;

		document.getElementById("dbScrollArea").scrollLeft = animation.beginPosition - change;
		animation.intervalCount ++;
	}
}
