//***************************************************************************************
//**************************  Adjustable Constants  *************************************
//**																				   **
	  var NUM_BANNERS;	//total number of banners, can be modified to be dynamic   	   **
//**					Update: now set in setTimer(), called from template			   **
//**														   						   **
 	  var TIME_LENGTH = 6000; // length each banner is visible in milliseconds         **
//**																				   **
//***************************************************************************************
//***************************************************************************************



//**************************************************************************
//*************************  Do not change these  **************************

var banner_id;		//the internal int id of the banner
					//set banner so it will start at 0 in setCycle()
					//update: now set in setTimer(), called from template
									
var currTimer = -1;	//id for the timer, needed to cancel current timer on clicks



/************************************************************************
**  function setTimer(numBanners)
**
**		input:	integer number of banners
**		output:	void
**
**		desc: 	starting point for the timer loop.
**				sets the total number of banners and initializes the counter
**
*************************************************************************/
function setTimer(numBanners)
{
	NUM_BANNERS = numBanners;
	banner_id = NUM_BANNERS - 1
	
	setCycle(true);
}

/************************************************************************
**  function setCycle()
**
**		input:	Boolean "timer", true if the timer should continue, false otherwise
**		output:	void
**
**		desc: 	Increments the banner number and checks for bounds
**				Once id is updated, calls a func to retrieve content,
**				then loads content into divMain
**
*************************************************************************/
function setCycle(timer)
{
	//alert("Banner changing in setCycle()");
	if(++banner_id == NUM_BANNERS)
	{
		banner_id = 0;
	}
	setBanner(timer);
}

/************************************************************************
**  function setBanner()
**
**		input:	Boolean "timer", true if the timer should continue, false otherwise
**		output:	void
**
**		desc: 	Based on the banner id set previously, choose and load
**				the correct content markup for the banner.  Then cycles
**				through the number of banners (maintain extensibility) to
**				create the markup for thumbnails for each banner ad.  This
**				allows the user to click and load the banner of their choice.
**
**		update: changed method to support dynamic number of banners, using 
**				a for loop instead of listing each possible assignment, then
**				branching through a switch block. (2008.07.08)
**
*************************************************************************/
function setBanner(timer)
{
	var n = 0;
	var p = "";
	var t = "";
	
	for(;n < NUM_BANNERS; n++)
	{
		p = "promo" + (n + 1);
		t = "thumb" + (n + 1);
		if(n != banner_id)
		{
			document.getElementById(p).className = "promoTile";
			document.getElementById(t).className = "thumbnail";
		}
		else
		{
			document.getElementById(p).className = "currPromoTile";
			document.getElementById(t).className = "currThumbnail";
		}
	}	
	
	if(timer)
		currTimer = setTimeout("setCycle(true);", TIME_LENGTH);
}



/************************************************************************
**  function setBannerNumber()
**
**		input:	integer "i" - representing the banner id
**				boolean "timer" - whether or not to resume rotation

**		output:	void
**
**		desc: 	This handles a user clicking on a thumbnail to load a banner
**				out of order.  The current timer must be stopped first, then
**				i is adjusted for zero-indexing, the delay boolean is reset
**				to trigger a fresh load, then the timer is reset.
**
**		updates: Changed method to support any number of banners. (2008.07.08)
**				when a user click on thumbnail, stop the rotation (2008.08.19)
**				when a user hover and removes mouse, resume rotation (2008.08.19)
*************************************************************************/
function setBannerNumber(i, timer)
{
	//stop the current timed interval, or we will have multiple timers executing
	if(currTimer != -1)
	{
		clearTimeout(currTimer);
		currTimer = -1;
	}
	
	//assign the correct banner number
	switch(i)
	{
		case 0:
			banner_id = NUM_BANNERS - 1;
			break;
		default:
			banner_id = i - 1;
			break;
	}
	
	
	setCycle(timer);
}

var insideBannerId;



/************************************************************************
**  function pauseRotation()
**
**		input:	String "banner", the id of the banner affected
**		output:	void
**
**		desc: 	When a user mouses over a banner, rotation of the group
**				halts so the banner can be read.  Tests for rotation to 
**				be stopped already.
**
**		update: initial revision (2008.08.19)
**
*************************************************************************/
function pauseRotation(banner)
{
	//alert("Pausing on banner: " + banner);
	var temp = document.getElementById(banner);
	insideBannerId = temp.id.charAt(temp.id.length - 1) * 1; //cast to int
	
	//alert(insideBannerId);
	
	if(currTimer != -1)
	{
		clearTimeout(currTimer);
		currTimer = -1;
	}
}


/************************************************************************
**  function resumeRotation()
**
**		input:	String "banner", the id of the banner affected
**		output:	void
**
**		desc: 	When a user mouses over a banner, rotation of the group
**				halts so the banner can be read.  Tests for rotation to 
**				be stopped already.
**
**		update: initial revision (2008.08.19)
**
*************************************************************************/
function resumeRotation(banner)
{
	//alert("Resuming on banner: " + banner);
	
	setBannerNumber(insideBannerId - 1, true);
}

