var delay = new Array();
var numElements = new Array();
var index = new Array();
var timeOutID = new Array();
var isRunning = new Array();


/*
 * Name:
 *	getElement
 *
 * Description:
 *	Returns an element searched by name or id
 *
 * Pre-conditions:
 *	elName		REQUIRED	Id or name of element
 *
 * Post-conditions:
 *	The element is returned
 */

function getElement(elName) {

	if (document.getElementByName) {
		return document.getElementByName(elName);
		
	} else if (document.getElementById) {
		
		return document.getElementById(elName);
		
	} else {
		
		return false;
		
	} 
	
} // END function - getElement



/*
 * Name:
 *	updaterotatorText
 *
 * Description:
 *	increments index for this boxId and changes
 *	rotatorContent's innerHTML to that of the index's
 *
 * Pre-conditions:
 *	boxId		REQUIRED	stnBoxId string
 *
 * Post-conditions:
 *	rotatorContent_boxId is updated
 *
 */
function updaterotatorText(boxId)
{
	var updateDiv;
	var rotatorContent;
	index[boxId]++;
		
	if(index[boxId] + 1 > numElements[boxId])
	{
		index[boxId] = 0;
	}
	
	updateDiv = getElement("hidden_" + boxId + '_' + index[boxId]);
	rotatorContent = getElement("rotatorcontent_" + boxId);
	rotatorContent.innerHTML = updateDiv.innerHTML;

	timeOutID[boxId] = setTimeout('updaterotatorText(\'' + boxId + '\')', delay[boxId]);
	
	isRunning[boxId] = true;
} //END function updaterotatorText


/*
 * Name:
 *	backrotatorText
 *
 * Description:
 *	decrements index, sets rotatorContet's innerHTML to the 
 *	index's hidden div
 *
 * Pre-conditions:
 *	boxId		REQUIRED	stnBoxId string
 *
 * Post-conditions:
 *	rotatorContent_boxId is updated, index is decremented
 *
 */
function backrotatorText(boxId)
{
	var updateDiv;
	var rotatorContent;

	if(isRunning[boxId])
	{
		clearTimeout(timeOutID[boxId]);
		isRunning[boxId] = false;
	}
	index[boxId]--;
	if(index[boxId] < 0)
	{
		index[boxId] = numElements[boxId] - 1;
	}
	
	updateDiv = getElement("hidden_" + boxId + '_' + index[boxId]);
	rotatorContent = getElement("rotatorcontent_" + boxId);
	rotatorContent.innerHTML = updateDiv.innerHTML;
	
} //END function backrotatorText

/*
 * Name:
 *	forwardrotatorText
 *
 * Description:
 *	increments index for this boxId and changes
 *	rotatorContent's innerHTML to that of the index's
 *
 * Pre-conditions:
 *	boxId		REQUIRED	stnBoxId string
 *
 * Post-conditions:
 *	rotatorContent_boxId is updated, index is incremented
 *
 *
 */
function forwardrotatorText(boxId)
{


	var updateDiv;
	var rotatorContent;

	if(isRunning[boxId])
	{
		clearTimeout(timeOutID[boxId]);
		isRunning[boxId] = false;
	}
	index[boxId]++;

	if(index[boxId] + 1 > numElements[boxId])
	{
		index[boxId] = 0;
	}
	


	updateDiv = getElement("hidden_" + boxId + '_' + index[boxId]);

	rotatorContent = getElement("rotatorcontent_" + boxId);

	rotatorContent.innerHTML = updateDiv.innerHTML;
}


/*
 * Name:
 *	selectrotatorText
 *
 * Description:
 *	selects specific item using the index and changes
 *	rotatorContent's innerHTML to that of the index's
 *
 * Pre-conditions:
 *	boxId		REQUIRED	stnBoxId string
 *	idx  		REQUIRED	Index string
 *
 * Post-conditions:
 *	rotatorContent_boxId is updated
 *
 *
 */
function selectrotatorText(boxId,idx)
{


	var updateDiv;
	var rotatorContent;

	index[boxId] = idx;


	updateDiv = getElement("hidden_" + boxId + '_' + index[boxId]);

	rotatorContent = getElement("rotatorcontent_" + boxId);

	rotatorContent.innerHTML = updateDiv.innerHTML;
}




/*
 * Name:
 *	pauserotatorText
 *
 * Description:
 *	stops the rotator
 *
 * Pre-conditions:
 *	boxId		REQUIRED	stnBoxId string
 *
 * Post-conditions:
 *	rotatorText is stopped
 *
 */
function pauserotatorText(boxId)
{
	if(isRunning[boxId])
	{
		clearTimeout(timeOutID[boxId]);
		isRunning[boxId] = false;
	}
} //END function - pauserotatorText

/*
 * Name:
 *	startrotatorText
 *
 * Description:
 *	starts rotator
 *
 * Pre-conditions:
 *	boxId		REQUIRED	stnBoxId string
 *
 * Post-conditions:
 *	rotatorContent_boxId is updated
 *
 */

function startrotatorText(boxId)
{

	if(isRunning[boxId])
	{
		clearTimeout(timeOutID[boxId]);
		isRunning[boxId] = false;
	}
	
	timeOutID[boxId] = setTimeout('updaterotatorText(\'' + boxId + '\')', delay[boxId]);
	isRunning[boxId] = true;
} //END function startrotatorText
