function die(error) {
  alert(error);
  throw error;
}

function getObjectFunction(object,
                           functionPointer) {
  if (!functionPointer) {
    throw new Error("Can't create function with null function pointer");
  }
  return function(a1, a2, a3, a4, a5, a6, a7) {
    functionPointer.call(object, a1, a2, a3, a4, a5, a6, a7);
  }
}

/* gets the x and y pixel position of any node */
function getOffset(node) {
  var result = {x:0, y:0};
  var currentNode = node;
  while (currentNode != null) {
    result.x += currentNode.offsetLeft;
    result.y += currentNode.offsetTop;
    currentNode = currentNode.offsetParent;
  }
  return result;
}

/* dom */
  function getText(div) {
    if (!div.firstChild) return "";
    return div.firstChild.nodeValue;
  }

  function getEvent(event) {
    if (!event) {
      return new IEEventWrapper(window.event, true, true);
    }
    return event;
  }

  function IEEventWrapper(event, bubbles, cancelable) {
    this.pEvent = event;
    this.type = event.type;
    this.target = event.srcElement;  //pEvent.fromElement;
    this.currentTarget = event.srcElement;
    this.eventPhase = 3;
    this.bubbles = bubbles;
    this.cancelable = cancelable;
    this.timeStamp = new Date().getTime();

    // for mouse event
    this.screenX = event.screenX;
    this.screenY = event.screenY;
    this.clientX = event.clientX;
    this.clientY = event.clientY;
    this.ctrlKey = event.ctrlKey;
    this.shiftKey = event.shiftKey;
    this.altKey = event.altKey;
    this.metaKey = event.metaKey;
    this.button = event.button;
    this.relatedTarget = null;
  }
  IEEventWrapper.prototype.CAPTURING_PHASE   = 1;
  IEEventWrapper.prototype.AT_TARGET         = 2;
  IEEventWrapper.prototype.BUBBLING_PHASE    = 3;

  // ie can only have one listener anyways.
  IEEventWrapper.prototype.stopPropagation = function() {}

  IEEventWrapper.prototype.preventDefault = function() {
    this.pEvent.cancelBubble = true;
    this.pEvent.returnValue=false;
  }

/* css */
  function getElementsByClass(searchClass,node,tag) {
    var classElements = new Array();
    if ( node == null )
      node = document;
    if ( tag == null )
      tag = '*';
    var els = node.getElementsByTagName(tag);
    var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
    for (i = 0; i < els.length; i++) {
      if ((searchClass == "") || pattern.test(els[i].className)) {
        classElements.push(els[i]);
      }
    }
    return classElements;
  }

  function addClass(element, className) {
    var classes = element.className.split(" ");
    if (!classes.contains(className)) {
      classes.add(className);
    }
    element.className = classes.join(" ");
  }
  function removeClass(element, className) {
    var classes = element.className.split(" ");
    if (classes.contains(className)) {
      classes.remove(className);
    }
    element.className = classes.join(" ");
  }
