function $(id) {
  return document.getElementById(id);
}

function getPageOffsetTop(el) {

  var y;

  // Return the y coordinate of an element relative to the page.

  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);

  return y;
}

function hasClassName(el, name) {

  var i, list;

  // Return true if the given element currently has the given class
  // name.

  list = el.className.split(" ");
  for (i = 0; i < list.length; i++)
    if (list[i] == name)
      return true;

  return false;
}

function removeClassName(el, name) {

  var i, curList, newList;

  if (el.className == null)
    return;

  // Remove the given class name from the element's className property.

  newList = new Array();
  curList = el.className.split(" ");
  for (i = 0; i < curList.length; i++)
    if (curList[i] != name)
      newList.push(curList[i]);
  el.className = newList.join(" ");
}

function addWindowEvent(fn, evt) {
  if (typeof(window["on" + evt]) == "function") {
    var oldfn = window["on" + evt];
    window["on" + evt] = function() {
      oldfn();
      fn();
    }
  }
  else {
    window["on" + evt] = function() { fn(); };
  }
}

function addLoadEvent(fn) {
  if (typeof(window.onload) == "function") {
    var oldfn = window.onload;
    window.onload = function() {
      oldfn();
      fn();
    }
  }
  else {
    window.onload = function() { fn(); };
  }
}