var scrollanim = {time:0, begin:0, change:0.0, duration:0.0, element:null, timer:null};
var timerscroll;
var timerscroll_time = 20000;
$(document).ready(function () {
	timerscroll = setInterval("ScrollArrow('right','banner','banner1')", timerscroll_time);
});

var currentSection = "banner1";
var tabTag = "";
var paneTag = "";

function ScrollSection(link, scrollArea, offset)
{
	if (currentSection == link) {
		return;
	}
	lastSection = currentSection;
	currentSection = link;
	
	clearInterval(timerscroll);
	timerscroll = setInterval("ScrollArrow('right','banner','banner1')", timerscroll_time);
	
	theScroll = document.getElementById(scrollArea);
	position = findElementPos(document.getElementById(link));
	
	if (offset != "") {
		offsetPos = findElementPos(document.getElementById(offset));
		position[0] = position[0] - offsetPos[0];
	}

	scrollStart(theScroll, theScroll.scrollLeft, position[0], "horiz");
}

function ScrollArrow(direction, scrollArea, offset) {
	
	clearInterval(timerscroll);
	timerscroll = setInterval("ScrollArrow('right','banner','banner1')", timerscroll_time);
	
	toolbarNames = new Array();
	toolbarNames.push('banner1');
	toolbarNames.push('banner2');
	toolbarNames.push('banner3');
	toolbarNames.push('banner4');

	for (var i = 0; i < toolbarNames.length; i++) {
		if (toolbarNames[i] == currentSection) 
		{
			if (direction == "left") {
				if (i - 1 < 0) {
					gotoTab = toolbarNames[toolbarNames.length - 1];
				} else {
					gotoTab = toolbarNames[i - 1];
				}
			} 
			else 
			{
				if ((i + 1) > (toolbarNames.length - 1)) {
					gotoTab = toolbarNames[0];
				} else {
					gotoTab = toolbarNames[i + 1];
				}
			}
		}
	}
	
	ScrollSection(gotoTab, scrollArea, offset);

}

function scrollStart(elem, start, end, direction)
{
	if (scrollanim.timer != null) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;
	}
	scrollanim.time = 0;
	scrollanim.begin = start;
	scrollanim.change = end - start;
	scrollanim.duration = 30;
	scrollanim.element = elem;
	
	if (direction == "horiz") {
		scrollanim.timer = setInterval("scrollHorizAnim();", 15);
	}
	else {
		scrollanim.timer = setInterval("scrollVertAnim();", 15);
	}
}

function scrollVertAnim()
{
	if (scrollanim.time > scrollanim.duration) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;
	}
	else {
		move = sineInOut(scrollanim.time, scrollanim.begin, scrollanim.change, scrollanim.duration);
		scrollanim.element.scrollTop = move; 
		scrollanim.time++;
	}
}

function scrollHorizAnim()
{
	if (scrollanim.time > scrollanim.duration) {
		clearInterval(scrollanim.timer);
		scrollanim.timer = null;
	}
	else {
		move = sineInOut(scrollanim.time, scrollanim.begin, scrollanim.change, scrollanim.duration);
		scrollanim.element.scrollLeft = move;
		scrollanim.time++;
	}
}
