// Dean Edwards/Matthias Miller/John Resig

// onDOMComplete functions
function init() {
    // quit if this function has already been called
    if (arguments.callee.done) return;

    // flag this function so we don't do the same thing twice
    arguments.callee.done = true;

    // kill the timer
    if (_timer) clearInterval(_timer);

    // do stuff
    startHovercraft('nav', 'LI');
    startPopupWindows();
};

/* for Mozilla/Opera9 */
if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", init, false);
}

/* ugly stuff for DOMContentLoaded in lesser browsers */

/* for Internet Explorer */
/*@ XX cc_on @*/
/*@ XX if (@_win32)
    document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
    var script = document.getElementById("__ie_onload");
    script.onreadystatechange = function() {
        if (this.readyState == "complete") {
            init(); // call the onload handler
        }
    };
/*@ XX end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
    var _timer = setInterval(function() {
        if (/loaded|complete/.test(document.readyState)) {
            init(); // call the onload handler
        }
    }, 10);
}

/* for other browsers */
window.onload = init;

/* useful missing DOM functions */

function is_all_ws( nod )
{
  // Use ECMA-262 Edition 3 String and RegExp features
  return !(/[^\t\n\r ]/.test(nod.data));
}

function is_ignorable( nod )
{
  return ( nod.nodeType == 8) || // A comment node
         ( (nod.nodeType == 3) && is_all_ws(nod) ); // a text node, all ws
}

function node_after( sib )
{
  while ((sib = sib.nextSibling)) {
    if (!is_ignorable(sib)) return sib;
  }
  return null;
}

function first_child( par )
{
  var res=par.firstChild;
  while (res) {
    if (!is_ignorable(res)) return res;
    res = res.nextSibling;
  }
  return null;
}

/* adds a class of "hover" to all <tag> items hovered over... for browsers
   without :hover */
startHovercraft = function(id, tag) {
  if (document.getElementById) {
    var navRoot = document.getElementById(id);
    for (i=0; i<navRoot.childNodes.length; i++) {
      var node = navRoot.childNodes[i];
      if (node.nodeName==tag) {
        node.onmouseover=function() {
        this.className+=" hover";
        }
      }
      node.onmouseout=function() {
        this.className=this.className.replace("hover", "");
      }
    }
  } 
}

/* ahhh... popups */
function popupWindow(link)
{
  var popup = window.open(link, '', 'width=550,height=280,scrollbars=yes,resizable=yes');
  return false;
}

startPopupWindows = function() {
  var links = document.getElementsByTagName('a');
  for (var i = 0; i < links.length; i++)
  {
    if (links[i].rel == 'popup')
    {
      links[i].onclick = function() { return popupWindow(this.href) }
    }
  }
};


