/*
 * Functions and vars for divSlide animation.
 */

var curSlide 		= "pane-01";		// This is the default pane. 
var tabPre 			= "tab-";		// ID of all navigation tabs begin with this.
var slidePre 		= "pane-";		// ID of all panes/sections begin with this.
var slideInterval 	= 25;			// The higher the number, the slower the animation.
var scrollAnimation	= {time:0, begin:0, change:0.0, duration:0.0, element:null, timer:null};



function getElPosition(elemFind)
{
	var elemX = 0;
	var elemY = 0;
	do 
	{
		elemX += elemFind.offsetLeft;
		elemY += elemFind.offsetTop;
	} 
	while ( elemFind = elemFind.offsetParent )

	return Array(elemX, elemY);
}

function animateHorizontal()
{
	if (scrollAnimation.time > scrollAnimation.duration) 
	{
		clearInterval(scrollAnimation.timer);
		scrollAnimation.timer = null;
	}
	else 
	{
		move = animateSpeed(scrollAnimation.time, scrollAnimation.begin, scrollAnimation.change, scrollAnimation.duration);
		scrollAnimation.element.scrollLeft = move;
		scrollAnimation.time++;
	}
}

function animateSlide(link, scrollArea, offset)
{
	if (curSlide == link) 
	{
		return;
	}
	lastSection = curSlide;
	curSlide = link;

    sectionTab = tabPre + curSlide.split("-")[1];
    document.getElementById(sectionTab).className = "active";
    if (lastSection) 
	{
	    lastTab = tabPre + lastSection.split("-")[1];
	    document.getElementById(lastTab).className = "inactive";
	}
	
	theScroll = document.getElementById(scrollArea);
	position = getElPosition(document.getElementById(link));
	if (offset != "") 
	{
		offsetPos = getElPosition(document.getElementById(offset));
		position[0] = position[0] - offsetPos[0];
	}

	animateStart(theScroll, theScroll.scrollLeft, position[0]);
}

function animateSpeed(stime, sstart, schange, sduration)
{
	return -schange/2 * (Math.cos(Math.PI * stime/sduration) - 1) + sstart;
}

function animateStart(elem, start, end)
{
	if (scrollAnimation.timer != null) 
	{
		clearInterval(scrollAnimation.timer);
		scrollAnimation.timer = null;
	}
	scrollAnimation.time = 0;
	scrollAnimation.begin = start;
	scrollAnimation.change = end - start;
	scrollAnimation.duration = 25;
	scrollAnimation.element = elem;
	scrollAnimation.timer = setInterval("animateHorizontal();", slideInterval);
}





