// 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 = [];

function initAll() {
  // copy the ads into the array
  for (i=0; i<numSmallAds; i++) {
		  smallAds[i] = document.getElementById("buttonAd"+i).innerHTML;
				}
  showSmallAds();
	 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
  }
		

