// This function switches between the aspect pages in the tabbed dialog.

function pChangeAspect(psAspectName, piSelectedAspect, piFirstAspect, piLastAspect)
{
	var iPtr;
	var sTabID;
	var sContentID;
	var oTabElement;
	var oContentElement;

	for ( iPtr = piFirstAspect ; iPtr <= piLastAspect ; iPtr ++ )
	{
		sTabID = psAspectName + "Aspect" + iPtr + "Tab";	
		oTabElement = document.getElementById(sTabID);

		sContentID = psAspectName + "Aspect" + iPtr + "Content";	 
		oContentElement = document.getElementById(sContentID);

		if (iPtr == piSelectedAspect)
		{
			oTabElement.className = "current";
			oContentElement.style.display = "block";
		}
		else
		{
			oTabElement.className = "";
			oContentElement.style.display = "none";
		}
	}
}



// This javascript runs the image switch timers on the aspect pages
// It relies on the switchImages function being rendered in the Items XML.
// To start the timer, run initialiseTimer() from the window.onload funcion
var seconds;
var timerID = null;
var timerRunning = false;
var delay = 1000;

function initializeTimer()
{
	// Set the length of the timer, in seconds
	seconds = 10;
	stopTheTimer();
	startTheTimer();
}

function stopTheTimer()
{
	if(timerRunning)
	{
		clearTimeout(timerID);
	}
	timerRunning = false;
}

function startTheTimer()
{
	if (seconds==0)
	{
		stopTheTimer();
		
		// switchImages() is created within the Item Rendering XSL
		switchImages();
		
		initializeTimer();
	}
	else
	{
		seconds --;
		timerRunning = true;
		timerID = self.setTimeout("startTheTimer()", delay)
	}
}

