var g_hdl_modulePromoRotateTimeout = null; //!< Handle for the timeout on the rotation.
var g_modulePromoCurrPromo = 1; //!< modules are 1 indexed
var g_modulePromoTotalPromos = 0; //!< total number of promo items
var g_modulePromoTimeToDisplay = 0; //!< The time, in milliseconds, the rotation should 'pause'.

/*--------------------------------------------------------------------------*/
/**
	@brief Used to change the promo which is currently displayed.
	This method performs the "rotation" service and it is set to run 
	at an interval (in seconds) that is configured by the user.
 */
function cyclePromos() { /* <<<( */

	// check that there are promos to display
	if (0 < g_modulePromoTotalPromos) {

		// hide current promo
		if (null != document.getElementById('module-promo-content-container-' + g_modulePromoCurrPromo)) {
			document.getElementById('module-promo-content-container-' + g_modulePromoCurrPromo).style.display = 'none';
		}

		// move to next promo
		g_modulePromoCurrPromo++;

		// determine if at end of promo list
		if (g_modulePromoTotalPromos < g_modulePromoCurrPromo) {

			// reset to starting promo
			g_modulePromoCurrPromo = 1;
		}

		// display next promo
		if (null != document.getElementById('module-promo-content-container-' + g_modulePromoCurrPromo)) {
			document.getElementById('module-promo-content-container-' + g_modulePromoCurrPromo).style.display = 'block';
		}

		// verify that the hdl for the timeout is not currently being used
		if (null != g_hdl_modulePromoRotateTimeout) {
			// if it is, reset the timeout
			clearTimeout(g_hdl_modulePromoRotateTimeout);
		}
		g_hdl_modulePromoRotateTimeout = setTimeout(cyclePromos, g_modulePromoTimeToDisplay);
	}

	return;
} /* )>>> */

/*--------------------------------------------------------------------------*/
/**
	@brief Used to start the 'rotation' of the promos.
	This method also correctly formats the configurable rotation time
	into milliseconds.

	@param displayTime Int containing the number of seconds the rotation
	should 'pause' for an promo.
 */
function startPromoCycle(displayTime) { /* <<<( */

	// set time to display in milliseconds
	g_modulePromoTimeToDisplay = displayTime * 1000;

	// verify that the hdl for the timeout is not currently being used
	if (null != g_hdl_modulePromoRotateTimeout) {
		// if it is, reset the timeout
		clearTimeout(g_hdl_modulePromoRotateTimeout);
	}
	// start cycle of promo items
	g_hdl_modulePromoRotateTimeout = setTimeout(cyclePromos, g_modulePromoTimeToDisplay);

	return;
} /* )>>> */

