// Rotate the Home Page Tiles, if present on the page
// **************************************************
// Set this to the number of the tile to start with!
currentTile=1 
// Set to the milliseconds for the rotation
rotateInterval=7000 // ms = 7 seconds
// Objects we'll need
thetimer=null;
howManyTiles=0;

// This just runs ONCE on PAGE_LOAD and sets up the rotation and all the associated events
jQuery(document).ready(function(){
	// See how many tiles we have (if any - this code is in the footer, so there may not be any tiles to rotate!)
	howManyTiles=jQuery('.box-banner-large .list-nav li').length;
	if (howManyTiles>0)
	{
		// Set an event to stop the timer if the user mouses over the tile
		jQuery('.box-banner-large').mouseenter(function() {
			// Stop your timer here
			clearTimeout(theTimer);
		});
		// Set an event to restart the timer once the mouse moves away fro the tile
		jQuery('.box-banner-large').mouseleave(function() {
			// Start your timer here
			theTimer=setTimeout('showNext()',rotateInterval);
		});	
		
		// If the currentTile is not the tile being shown, show it!
		// This allows us to jump straight to a tile if desired.
		if (currentTile > 1) showTile(currentTile);

		// Start a timer to kick off the rotation
		theTimer=setTimeout('showNext()',rotateInterval);
	}
});

// This increments the "currentTile", shows it and resets the timer
function showNext()
{
	// Increment to the next tile
	currentTile+=1; 
	// Check to make sure we are not going out of bounds
	// and if so, start back with the 1st tile.
	if (currentTile > howManyTiles) currentTile=1;
	// Show the tile.
	showTile(currentTile);
	// Reset the timer
	theTimer=setTimeout ('showNext()', rotateInterval);
}

// This just shows the desired tile... by number
function showTile(whichOne)
{	
	_this = jQuery(".box-banner-large .list-nav li").eq(whichOne-1).find('a');
	_container = _this.parents('.box-banner-large');
	_container.find('.list-nav').find('li').removeClass();
	_this.parent().addClass('selected');
	_container.find('.list-content').find('li').fadeOut();
	_container.find('.list-content').find(_this.attr('href')).fadeIn();
	return false; 	
}
