var mac = /Konqueror|Safari|KHTML/.test(navigator.userAgent);
var pages = [0, 0, 0];

// Lookup an HTML element.
// (Same as $("blah") in prototype.js, without overhead.)
function e(id) {
  if (document.getElementById)
    return(document.getElementById(id));
  else if (document.all)
    return(document.all[id]);
  return(null);
}

// Get position relative to top left corner of document.
function position(e) {
  var x = 0;
  var y = 0;
  do {
    x += e.offsetLeft || 0;
    y += e.offsetTop  || 0;
    if (mac && e.offsetParent == document.body &&
      e.style["position"] == "absolute")
      break;
  } while (e = e.offsetParent);
  return [x, y];
}

// Toggle banners in splash page.
function show_toggle(n) {

  // Close old one if one already open and moving to new one.
  if (pages[1] && n != 1) {
    e("page1").style.display = "none";
    pages[1] = 0;
  }
  if (pages[2] && n != 2) {
    e("page2").style.display = "none";
    pages[2] = 0;
  }
  if (pages[3] && n != 3) {
    e("page3").style.display = "none";
    pages[3] = 0;
  }

  // Turn the current one on or off.
  e("page"+n).style.display = pages[n] ? "none" : "block";
  pages[n] = !pages[n]

  // Scroll down to top of banner (or back to top if closing).
  var sx = document.documentElement.scrollLeft || document.body.scrollLeft;
  if (pages[n]) {
    var pos = position(e("splash"+n));
    window.scrollTo(sx, pos[1]);
  } else {
    window.scrollTo(sx, 0);
  }

  // Save which one we were last interested in so we know which colors to
  // use if, say, user clicks on one of the account links.
  if (pages[n])
    document.cookie = "ways_banner="+n+"&home";
}

// Highlight/unhighlight tabs in banners.
function over(n, tab, on, do_bg) {
  e("tab_fg" + n + tab).style.color = on ? "#C0A000" : "black";
  if (do_bg)
    e("tab_bg" + n + tab).style.background = on ?
      "url(\"/images/banner/fade_left"+n+".gif\") repeat-y 100%" : "transparent";
}

// Clicked on a tab.
function click(url) {
  window.location = url;
}
