// This manages the small button ads on the right side.
// It copies the ads into an array, then every minute random sorts them and displays them again

window.onload = initAll;

var smallAds = [];
var fred = 0;   // 0 means not defined yet, 1 is Fred's and 2 is Freelap, alternates

function initAll() {
  // copy the ads into the array
  for (i=0; i<numSmallAds; i++) {
		  smallAds[i] = document.getElementById("buttonAd"+i).innerHTML;
				}
 showSmallAds();
 fred = Math.floor(2.0*Math.random()+1.0);
 displayFredAd();			
	if (window.raceID !== undefined && raceID>0)
	  jsRaceInitAll()
	if (window.jsInit)
	  jsInit()
	if (window.date !== undefined && date != '')
	  checkDate();		// this is in races.php to look for changes to the date via the calendar
 }

function randOrd(){
  return (Math.round(Math.random())-0.5); 
		}

function showSmallAds() {
		var s = "";
  for (i=0; i<smallAds.length; i++) {
    document.getElementById("buttonAd"+i).innerHTML = smallAds[i];
    }	
	 smallAds.sort(randOrd);  // randomize for next call
		setTimeout("showSmallAds()", 60 * 1000);    // display the ads randomly every 1 minute
  }
		
function displayFredAd() {
  //if (fred == 1) {
    document.getElementById("fred").innerHTML = '<a href="http://www.sportstiminginternational.com" target="_blank"><img src="images/ad_microtab2.jpg" width="392" height="72" border="0"></a>';
		//  fred = 2;
		//		}
		//else {
  //  document.getElementById("fred").innerHTML = '<a href="http://www.freelap-usa.com" target="_blank"><img src="images/ad_freelap2.gif" width="392" height="72" border="0"></a>';
		//  fred = 1;
		//  }		
		//setTimeout("displayFredAd()", 10 * 900);    // swap ads every 9 seconds
  }

