// ---------------------------------------------------------------------
// Convience DOM enhancements.
// ---------------------------------------------------------------------

// ---------------------------------------------------------------------
// Some standard functions from the Prototype library.
// http://prototype.conio.net/

function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }

  return elements;
}

document.getElementsByClassName = function(className, parentElement) {
  var children = ($(parentElement) || document.body).getElementsByTagName('*');
  return $A(children).inject([], function(elements, child) {
    if (child.className.match(new RegExp("(^|\\s)" + className + "(\\s|$)")))
      elements.push(child);
    return elements;
  });
}

// ---------------------------------------------------------------------
// Firefox does not have an element.contains() method, and Safari has
// an incorrect implementation. So let's do something about it.

function dnContains (node) {
	if (node == null)
		return false;
	if (node == this)
		return true;
	else
		return this.contains(node.parentNode);
}

// Firefox/Mozilla
if (window.HTMLElement && !window.HTMLElement.prototype.contains)
    window.HTMLElement.prototype.contains = dnContains;

// Safari
if (window["[[DOMElement.prototype]]"]) {
    // Test that the contains() bug is still present.
    var n1 = document.createElement("p");
    var n2 = document.createElement("em");
    if (n1.contains(n2))
        window["[[DOMElement.prototype]]"].contains = dnContains;
}

// ---------------------------------------------------------------------
