window.onload = initBannerLink;

var thisAd = 0;

function initBannerLink(){
  //检查 adBanner 是否是包含在 <a> 中
  if(document.getElementById("adBanner").parentNode.tagName == "A"){
		//设置 <a> 的 onclick 事件调用 newLocaton 函数
    document.getElementById("adBanner").parentNode.onclick = newLocation;
  }
  rotate();
}

function newLocation(){
  var adURL = new Array("negrino.com", "sun.com", "microsoft.com");
  document.location.href = "http://www." + adURL[thisAd];
  return false; //不用在加载 href 了，JavaScript 已经处理好了
}

function rotate(){
  var adImages = new Array("images/banner1.gif", "images/banner2.gif", "images/banner3.gif");
  thisAd++;
  if(thisAd == adImages.length){
    thisAd = 0;
  }
  document.getElementById("adBanner").src = adImages[thisAd];
	
  setTimeout(rotate, 2000);
}