/*
 * Name:
 *	js_flipper_functions.js
 *
 * Description:
 *	Defines functions for the JSFlipper Box
 *
 * Pre-conditions:
 *	None
 *
 * Post-conditions:
 *	Defines the following functions:
 *
 * Log:
 *	Doug Mears			created 4/28/2006
 *	
 */


/*
 * Name:
 *	updateFlipperText
 *
 * Description:
 *	increments index for this boxId and changes
 *	flipperContent's innerHTML to that of the index's
 *
 * Pre-conditions:
 *	boxId		REQUIRED	stnBoxId string
 *
 * Post-conditions:
 *	flipperContent_boxId is updated
 *
 * Log:
 *	Doug Mears			5/8/2006
 *	- Creation
 *
 */
/*function updateFlipperText(boxId)
{
	var updateDiv;
	var flipperContent;
	index[boxId]++;
		
	if(index[boxId] + 1 > numElements[boxId])
	{
		index[boxId] = 0;
	}
	
	updateDiv = getElement("hidden_" + boxId + '_' + index[boxId]);
	flipperContent = getElement("flipperContent_" + boxId);
	flipperContent.innerHTML = updateDiv.innerHTML;

	timeOutID[boxId] = setTimeout('updateFlipperText(\'' + boxId + '\')', delay[boxId]);
	
	isRunning[boxId] = true;
} //END function updateFlipperText
*/

/*
 * Name:
 *	backFlipperText
 *
 * Description:
 *	decrements index, sets flipperContet's innerHTML to the 
 *	index's hidden div
 *
 * Pre-conditions:
 *	boxId		REQUIRED	stnBoxId string
 *
 * Post-conditions:
 *	flipperContent_boxId is updated, index is decremented
 *
 * Log:
 *	Doug Mears			5/8/2006
 *	- Creation
 *
 *  Ramu                07/17/2007
 *   - if feature Expired moving back to next feature
 */
function backFlipperText(boxId)
{
	var updateDiv;
	var flipperContent;
	//
	//if feature exists, 
	//
	if((index[boxId] >= 0) && (index[boxId] < numElements[boxId]))
	{
		if(isRunning[boxId])
		{
			clearTimeout(timeOutID[boxId]);
			isRunning[boxId] = false;
		}
		index[boxId]--;
		if(index[boxId] < 0)
		{
			index[boxId] = numElements[boxId] - 1;
		}
		// if feature fifo expired backward to next feature fifo
		if(getElement("hidden_" + boxId + '_' + index[boxId]) === null)
		{
			backFlipperText(boxId);
		} //end if feature fifo expired
		else
		{
			updateDiv = getElement("hidden_" + boxId + '_' + index[boxId]);
			flipperContent = getElement("flipperContent_" + boxId);
			flipperContent.innerHTML = updateDiv.innerHTML;
		}// end else
	}
} //END function backFlipperText

/*
 * Name:
 *	forwardFlipperText
 *
 * Description:
 *	increments index for this boxId and changes
 *	flipperContent's innerHTML to that of the index's
 *
 * Pre-conditions:
 *	boxId		REQUIRED	stnBoxId string
 *
 * Post-conditions:
 *	flipperContent_boxId is updated, index is incremented
 *
 *
 * Log:
 *	Doug Mears			5/8/2006
 *	- Creation
 *
 *  Ramu                07/17/2007
 *   - if feature Expired moving forward to next feature
 */
function forwardFlipperText(boxId)
{
	var updateDiv;
	var flipperContent;
	//if feature exist
	if((index[boxId] < numElements[boxId]) && (index[boxId] >= 0))
	{
		if(isRunning[boxId])
		{
			clearTimeout(timeOutID[boxId]);
			isRunning[boxId] = false;
		}
		index[boxId]++;
		if(index[boxId] + 1 > numElements[boxId])
		{
			index[boxId] = 0;
		}
		//if feature expired forward to next feature
		if(getElement("hidden_" + boxId + '_' + index[boxId]) === null )
		{
			forwardFlipperText(boxId);
		}// end if,feature fifo expired.
		else
		{
			updateDiv = getElement("hidden_" + boxId + '_' + index[boxId]);
			flipperContent = getElement("flipperContent_" + boxId);
			flipperContent.innerHTML = updateDiv.innerHTML;
		} // end else,
	}
}

/*
 * Name:
 *	pauseFlipperText
 *
 * Description:
 *	stops the flipper
 *
 * Pre-conditions:
 *	boxId		REQUIRED	stnBoxId string
 *
 * Post-conditions:
 *	flipperText is stopped
 *
 * Log:
 *	Doug Mears			5/8/2006
 *	- Creation
 *
 */
function pauseFlipperText(boxId)
{
	if(isRunning[boxId])
	{
		clearTimeout(timeOutID[boxId]);
		isRunning[boxId] = false;
	}
} //END function - pauseFlipperText

/*
 * Name:
 *	startFlipperText
 *
 * Description:
 *	starts flipper
 *
 * Pre-conditions:
 *	boxId		REQUIRED	stnBoxId string
 *
 * Post-conditions:
 *	flipperContent_boxId is updated
 *
 * Log:
 *	Doug Mears			5/8/2006
 *	- Creation
 *
 */

function startFlipperText(boxId)
{

	if(isRunning[boxId])
	{
		clearTimeout(timeOutID[boxId]);
		isRunning[boxId] = false;
	}
	
	timeOutID[boxId] = setTimeout('updateFlipperText(\'' + boxId + '\')', delay[boxId]);
	isRunning[boxId] = true;
} //END function startFlipperText
