/**
 * @author doug
 * requires that ajax_lib.js also be in the page 
 */
// Here is where we define the global array that gets used
var backGroundArray = new Array();
// call the function that builds up the array for use
populateBGArray();

/**
 * Just used as a single spot to build up the array of image objects we are going to use
 */
function populateBGArray()
{
	var theCount = 0;
	// Set the next offset to the current length
	theCount = backGroundArray.length;
	backGroundArray[theCount] = new MainBackground("mainImage1", "Free products, special offers and more inside...", "The TrackMaster Players Club", '/free');  

	theCount = backGroundArray.length;
	backGroundArray[theCount] = new MainBackground("mainImage2", "Manage your own stable...", "The TrackMaster Virtual Stable", '/stable');
   
	theCount = backGroundArray.length;
	backGroundArray[theCount] = new MainBackground("mainImage3", "Archived Results Charts...", "Request 1, 2 or 3+ Years of Historical Data", '/track/tch.htm');
   
	theCount = backGroundArray.length;
	backGroundArray[theCount] = new MainBackground("mainImage4", "Watch them win again...", "TrackMaster Race Replays", '/retail/rep.htm');

	theCount = backGroundArray.length;
	backGroundArray[theCount] = new MainBackground("mainImage5", "Winning made fun...", "TrackMaster Greg Harness Reports", '/harness/select/tmg.htm');

	theCount = backGroundArray.length;
	backGroundArray[theCount] = new MainBackground("mainImage6", "TrackMaster Blog...", "Read our posts and leave your comments", 'http://blog.trackmaster.com');
}

/**
 * Here is where the actual work of setting the main background image and text happens
 */
function setMainBackground()
{
   // first we get the time
   var currTime = new Date();
   var milliSecCount   = currTime.getTime();
   // now we see how many elements we have to deal with
   var theCount = backGroundArray.length;
   // and now figure out which to use
   var theOffset = milliSecCount % theCount;
   var theImageObject = backGroundArray[theOffset];
   // Next we get the element we need to set the background on
   var theImageDiv = getNodeRef("main");
   if (theImageDiv)
   {
      theImageDiv.className = theImageObject.whichStyleClass;
      // now set the text
      setInnerHTML("main_text", theImageObject.buildMainText());
   }
   else
   {
      setTimeout("setMainBackground()",200);
   }   
}

/**
 * An object to hold the info that gets put onto the home page for the main image
 * @param {Object} whichStyleClass the style sheet class to assign (which sets the image)
 * @param {Object} highlightText   The yellow highlight text to display
 * @param {Object} anchorText   The text to show in the link
 * @param {Object} anchorURL   Where to link to
 */
function MainBackground(whichStyleClass, highlightText, anchorText, anchorURL)
{
   this.whichStyleClass = whichStyleClass;
   this.highlightText = highlightText;
   this.anchorText = anchorText;
   this.anchorURL = anchorURL;
   // and now we assign the methods to the object
   this.buildMainText = buildMainText;
}

/**
 * The method of the object that will build the main text for home page display
 */
function buildMainText()
{
   var theText = "";
   theText = '<span class="yellow">' + this.highlightText + '</span>';
	theText += "\n<br />\n";
	theText += '<a href="' + this.anchorURL + '">' + this.anchorText + '</a> <a href="' + this.anchorURL + '"><img src="/images/yellow_arrow.gif" width="18" height="18" border="0" alt="TrackMaster" style="padding-left: 5px;" /></a>';
   return(theText);
}