//*********************************************
//The vars below relate to scrolling div windows
//*********************************************
var tabTag = "-tab";
var paneTag = "-pane";

//*********************************************
//Set the starting div for scrolling windows
//*********************************************

//Where
// aContainerName is the main Scrolling Window - i.e Container
// ------> aContainer should contain a single div that is the main scrolloing length
// -----------------> Inner single div contains only child divs from left to right and defined in that order

//Call VT_InitWindowScroller to add object props and set default display div
//Good values are 30 frames and a timerIncrements  of 10;

function VT_WindowScrollerInit(aContainerName,defaultChildDivName,defaultFirstDiv,totalFrames,timerIncrements,browserType,css)
{ 
	var ContainerObj,WindowObj;
	
	ContainerObj = VT_getObjectByID(aContainerName);	
	if (ContainerObj)
	{
		ContainerObj.VTX_browserType = browserType;
		ContainerObj.VTX_moveToDiv = defaultChildDivName;		
		ContainerObj.VTX_Timer = null;
		ContainerObj.VTX_Frames = totalFrames;
		ContainerObj.VTX_TimerIncrement = timerIncrements;
		ContainerObj.VTX_OnScroll = "DoScrollTimer();";
		WindowObj = VT_getObjectByID(ContainerObj.VTX_moveToDiv);
		document.VTX_ScrollObj = null;
		if (!WindowObj) 
		{
			return false;
		}				
		ContainerObj.VTX_FirstWindow = VT_getObjectByID(defaultFirstDiv);
		//calc the new x position of our containers offset
		posX = WindowObj.offsetLeft - ContainerObj.VTX_FirstWindow.offsetLeft;		
		ContainerObj.scrollLeft += posX - ContainerObj.scrollLeft;
		if(browserType && css){
			var o = VT_getObjectByID(ContainerObj.VTX_moveToDiv.split("-")[0] + tabTag);
			if(o)
			{
				o.className=css+browserType;
			}
		}
		return true;
	} else 
	{ 
		return false;
	}	
}

function movePanes(direction){
	if(direction =="right"){
		if(currentPane<totalPanes){currentPane++}else{currentPane=1}
	}
	if(direction =="left"){
		if(currentPane>1){currentPane--}else{currentPane=totalPanes}
	
	}
	return currentPane;
}

function VT_WindowScrollerMove(aContainerName,moveToDivName,css,cssSelect)
{
	var ContainerObj,WindowObj,S,o;
	//Only move if we're not on the current div	
	//debugger;
	ContainerObj = VT_getObjectByID(aContainerName);
	if (ContainerObj) 
	{				
		if (ContainerObj.VTX_moveToDiv == moveToDivName) 
		{
			return false;
		}
		//Need to make sure no other timers are running
		if (ContainerObj.VTX_Timer != null) 
		{
			clearInterval(ContainerObj.VTX_Timer);
			ContainerObj.VTX_Timer = null;

		}	
		//Kill the Scroll Objs Reference
		document.VTX_ScrollObj = null;	
		//Change to selection hightlighting
		if (ContainerObj.VTX_moveToDiv) 
		{
	   		if(css){
	   			
				S = ContainerObj.VTX_moveToDiv.split("-")[0] + tabTag;
				o = VT_getObjectByID(S);
				if(o)
				{
					o.className = css+ContainerObj.VTX_browserType;
				}
			}
		}

		ContainerObj.VTX_moveToDiv = moveToDivName;
		WindowObj = VT_getObjectByID(ContainerObj.VTX_moveToDiv);		
		//make sure its alive
		if (!WindowObj)
		{
			return false;
		}						
		
				
		// Change the section highlight.
		// Extract the root section name, and use that to change the background image to 'top', revealing the alt. state
		if(cssSelect){
			S = ContainerObj.VTX_moveToDiv.split("-")[0] + tabTag;
    		o = VT_getObjectByID(S);
    		if(o)
			{
    			o.className= cssSelect+ContainerObj.VTX_browserType;
   			}
   		}
		ContainerObj.VTX_Position = 0;		
		ContainerObj.VTX_ScrollStart = ContainerObj.scrollLeft;

		//calc the new x position of our containers offset
		posX = WindowObj.offsetLeft - ContainerObj.VTX_FirstWindow.offsetLeft;
		ContainerObj.VTX_ScrollLength = posX - ContainerObj.VTX_ScrollStart;
		ContainerObj.VTX_ScrollLength2 = ContainerObj.VTX_ScrollLength / 2;
		
		//Set our main reference
		document.VTX_ScrollObj = ContainerObj;
		ContainerObj.VTX_Timer = setInterval(ContainerObj.VTX_OnScroll, ContainerObj.VTX_TimerIncrement);	
		return true;	
	} else 
	{ 
		return false;
	}		
}

function DoScrollTimer()
{
	if (document.VTX_ScrollObj)
	{
		var ContainerObj = document.VTX_ScrollObj;	
		if (ContainerObj.VTX_Position > ContainerObj.VTX_Frames) 
		{
			//kill all the scroll objects
			clearInterval(ContainerObj.VTX_Timer);
			ContainerObj.VTX_Timer = null;
			document.VTX_ScrollObj = null;
					if(ContainerObj.VTX_moveToDiv=='page'+(productImages.length+1)+'-pane')
		{ContainerObj.scrollLeft = 0;VT_WindowScrollerMove("thumbcontainer","page" + movePanes("right") + "-pane","","");setPill('sliderDescription');}

		} else 
		{

			var x = Math.cos(Math.PI*ContainerObj.VTX_Position/ContainerObj.VTX_Frames) - 1;
			var posX =  -ContainerObj.VTX_ScrollLength2 * (x) + ContainerObj.VTX_ScrollStart;						
			ContainerObj.scrollLeft = posX;
			ContainerObj.VTX_Position = ContainerObj.VTX_Position + 1;

		}
	}
}
