// JavaScript Document

var thumbSetWidth = 290;
var curX = 0;
var animation;
var curSet = 1;
var newX;

function nextHandler()
{
	if(curSet != numOfSets)
	{
		curSet++; 
		animation = setInterval("animateNext()", 5);
	}
	evalButtons();
}

function previousHandler()
{
	if(curSet != 1)
	{
		curSet--; 
		animation = setInterval("animatePrevious()", 5);
	}
	evalButtons();
}

function animateNext() 
{
	if(curX > (0 -(curSet * thumbSetWidth)) + thumbSetWidth)
	{
		curX += Math.round((((0 -(curSet * thumbSetWidth)) + thumbSetWidth) - curX)/5);
		
		if(curX !== newX)
		{
			newX = curX;
			document.getElementById('thumbTable').style.left = curX + 'px';
		}
		else
		{
			clearInterval(animation);
			document.getElementById('thumbTable').style.left = curX + 'px';
		}
	}
	else
	{
		clearInterval(animation);
		curX = ((0 -(curSet * thumbSetWidth)) + thumbSetWidth);
		document.getElementById('thumbTable').style.left = curX + 'px';
	}
}

function animatePrevious() 
{
	
	if(curX < ((0+(curSet * thumbSetWidth)) - thumbSetWidth))
	{
		curX -= Math.round((((0+(curSet * thumbSetWidth)) - thumbSetWidth) + curX)/5);
		
		if(curX !== newX)
		{
			newX = curX;
			document.getElementById('thumbTable').style.left = curX + 'px';
		}
		else
		{
			clearInterval(animation);
			document.getElementById('thumbTable').style.left = curX + 'px';
		}
		
	}
	else
	{
		clearInterval(animation);
		curX = ((0+(curSet * thumbSetWidth)) - thumbSetWidth);
		document.getElementById('thumbTable').style.left = curX + 'px';
	}
}

function evalButtons()
{
	// Next Button display
	if(curSet == numOfSets)
	{
		document.getElementById('btnNext').src = "themes/xarBlueClover/images/btn_next_disabled.gif";
	}
	else
	{
		document.getElementById('btnNext').src = "themes/xarBlueClover/images/btn_next_active.gif";
	}
	
	if(curSet == 1)
	{
		document.getElementById('btnPrevious').src = "themes/xarBlueClover/images/btn_previous_disabled.gif";
	}
	else
	{
		document.getElementById('btnPrevious').src = "themes/xarBlueClover/images/btn_previous_active.gif";
	}
	
	
}
