window.onload = initBannerLink;

var adImages = new Array("../../images/ridematchAd4a.jpg","../../images/ms_advertise_ad2.jpg","../../images/calculator-ad2.gif","../../images/cc_polarbear.jpg");
var adURL = new Array("alt_transportation/Ridematch.shtml","marguerite/BusAdvertising.shtml","alt_transportation/calculator.shtml","alt_transportation/Commute_Club.shtml");

//construct an array of image captions
var altArray = new Array( 
"Share the commute to Stanford: Try our free Ridematching Service",
"Advertise in the Marguerite Shuttle",
"Commute cost and carbon emissions calculator: Find out the costs of your solo commute",
"Join the Commute Club");


function rotate() {

//pick a random ad index to start the loop
var thisAd =  Math.round(Math.random()*3);//returns integer from 0 to 3

	document.getElementById("adBanner").src = adImages[thisAd];
	document.getElementById("adBanner").alt = altArray[thisAd];
	if (document.getElementById("adBanner").parentNode.tagName == "A") {
		document.getElementById("adBanner").parentNode.href = "http://transportation.stanford.edu/" + adURL[thisAd];
	}

}

function initBannerLink() {
	
	rotate();
}
//---------------




function changepix(){
  //Generate a random number to select a URL in the array:
	//randomNumb = Math.round(Math.random()*4)+1;//returns integer from 1 to 5
	randomNumb = Math.round(Math.random()*3)+1;//returns integer from 1 to 3
	quotesrc=quoteArray[randomNumb];
	altsrc=altArray[randomNumb];
	heightsrc=heightArray[randomNumb];
	hrefsrc=hrefArray[randomNumb];
	
  //write to the HTML page:
	document.open();
	document.write ( '<a href=\"' + hrefsrc + '\"><img src=\"images/'  + quotesrc + '\" alt=\"' + altsrc + '\" width=\"240\" height=\"' + heightsrc + '\" border=\"0\"></a>'  );
	document.close();
}

