/* JavaScript Document */

// Master array for handling rotation of all rotating ads present.
var adsMasterArray = new Array();

// Function to add an ad position's info to the master array of ads.
function addToMasterArray(adPositionInfo)
{
  adsMasterArray[adsMasterArray.length] = adPositionInfo;
}

// Function to rotate the content of ALL the (rotating) ad positions.
function rotateAllAds()
{
  // For each ad listed in our master array...
  for(var i = 0; i < adsMasterArray.length; i++)
  {
    // Rotate the ad. 
    // FOR EACH ENTRY IN THE MASTER ARRAY, [0] is the array of ads, 
    // [1] is the current index, and [2] is the target div tag.
    adsMasterArray[i][1] = rotateAd(adsMasterArray[i][0], adsMasterArray[i][1], adsMasterArray[i][2]);
  }
}

// Function to rotate the content of a specific ad position.
function rotateAd(adsArray, adIndex, adDiv)
{
  // If there is more than one ad...
  if(adsArray.length > 1)
  {
    // Increment the current ad index.
    adIndex++;
    
    // If that took it past the last ad...
    if(adIndex >= adsArray.length)
    {
      // Start over with the first ad.
      adIndex = 0;
    }
    
    // Show the ad at the resulting index position.
    adDiv.innerHTML = adsArray[adIndex];
  }
  
  // Return the ad index.
  return adIndex;
}

// Set up a timer to rotate the ads.
var adsTimer = setInterval("rotateAllAds()", 6000);
