// Displays a short description when you roll over an ad number
//function AdOver(n) {
//  return ads_over_text[n-1];
//}

// Show the requested ad
function Jump2Ad(n) {
  clearTimeout(doNextAd);

  // Highlight the appropriate title in the list
  /*for (x=1;x<=ad_total;x++) {
    ad_list_id = "ad_list_" + x;
    ad_title_id = "ad_title_" + x;
    if (x==n) {
      eval("document.getElementById('"+ad_list_id+"').className = 'ad_list_on';");
      eval("document.getElementById('"+ad_title_id+"').className = 'ad_title_on';");
    }
    else {
      eval("document.getElementById('"+ad_list_id+"').className = 'ad_list_off';");
      eval("document.getElementById('"+ad_title_id+"').className = 'ad_title_off';");
    }
  }*/

  // Create the code to correctly display the image
  imgcode = '';
  if (ads_image[n-1].src.substr(ads_image[n-1].src.lastIndexOf(".")+1,3)=="swf") {
    imgcode += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="400" height="200">' +
  '<param name="movie" value="' + ads_image[n-1].src + '">' +
  '<param name="WMode" value="Transparent">' +
  '<param name="quality" value="high">' +
  '<embed src="' + ads_image[n-1].src + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="400" height="200" wmode="transparent"></embed>' +
'</object>';
  }
  else {
    imgcode += '<img src="' + ads_image[n-1].src + '" vspace="0" hspace="0" border="0">';
  }

  if (auto_url[n-1]==1) {
    imgcode = '<a href="/news_and_events/ad_detail.html?ad_id=' + ads_id[n-1] + '" target="_bottom">' + imgcode + '</a>';
  }
  else if (ads_url[n-1]!="") {
    imgcode = '<a href="' + ads_url[n-1] + '" target="_bottom">' + imgcode + '</a>';
  }

  document.getElementById('ads_image').innerHTML = imgcode;

  // Display the ad title and text
  if (auto_url[n-1]==1) {
    document.getElementById('ads_title').innerHTML = '<a href="/news_and_events/ad_detail.html?ad_id=' + ads_id[n-1] + '" target="_bottom">' + ads_title[n-1] + '</a>';
  }
  else if (ads_url[n-1]!="") {
    document.getElementById('ads_title').innerHTML = '<a href="' + ads_url[n-1] + '" target="_bottom">' + ads_title[n-1] + '</a>';
  }
  else {
    document.getElementById('ads_title').innerHTML = ads_title[n-1];
  }
  document.getElementById('ads_summary').innerHTML = ads_summary[n-1];

  // Resume play - show the pause image if the play was set
  if (document.getElementById('pause').src==navPlayImg.src) document.getElementById('pause').src = navPauseImg.src;

  // Prepare to show the next ad
  if (n==ad_total) nextAd = 1;
  else nextAd = n + 1;

  // Set the time to run this ad before showing the next one
  if (ad_total>1) doNextAd = setTimeout('Jump2Ad('+nextAd+')', ads_time[n-1]);
}

// Play or pause the ads
function pauseAds() {
  if (playflag==1) {
    clearTimeout(doNextAd);
    playflag = 0;
    document.getElementById('pause').src = navPlayImg.src;
  }
  else {
    Jump2Ad(nextAd);
    playflag = 1;
    document.getElementById('pause').src = navPauseImg.src;
  }
}

// Go to the previous ad
function goPrevAd() {
  if (nextAd<=2) Jump2Ad(ad_total-(2-nextAd));
  else Jump2Ad(nextAd-2);
  playflag = 1;
  document.getElementById('pause').src = navPauseImg.src;
}

// Go to the next ad
function goNextAd() {
  Jump2Ad(nextAd);
  playflag = 1;
  document.getElementById('pause').src = navPauseImg.src;
}

// Get the ad rotation started
function InitAds() {
  Jump2Ad(1);
}

