<!--//--><![CDATA[//><!--
sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
//--><!]]>

/* -----------------------------------------------------------------------------
    AuoNav 
    adds CSS class names to the LI elements of a nested UL list.
---------------------------------------------------------------------------------*/

  //config
  var menu_active_class = "active";
  var menu_leaf_class = "leaf";
  var menu_open_class = "open";
  var menu_closed_class = "closed";
  
  //the default page that is displayed if URL ends in /
  var menu_default_page = "";
  var menu_url;
  
  //main function
  //menu_id : id of the element containing the navigation
  function autonav(menu_id) {
     var url = location.href;
     if (url.lastIndexOf("/") == (url.length-1)) {
       url = url+menu_default_page;
     }
     if (url.lastIndexOf("?") >= 0) {
       url = url.substring(0, url.lastIndexOf("?"));
     }
     if (url.lastIndexOf("#") >= 0) {
       url = url.substring(0, url.lastIndexOf("#"));
     }
     menu_url = url;
     
     var main = document.getElementById(menu_id);
     if (!main) alert("No element with id '"+ menu_id +"' found");
     menu_traverse(main);
  }
  
  /* Walks down the lists and set properties on the way back
       returns set
             1: set = element is a node, unset = element is a leaf
             2: set = element contains the active node
             4: set = element is the active A node
  */
  function menu_traverse(element) {
    var props  = 0;
    
    // walk down
    for (var i=0; i<element.childNodes.length; i++) {
      var child = element.childNodes[i];
      props |= menu_traverse(child); // aggregate bits
    }
    
    // on the way back now
    switch (element.tagName) {
      case "UL":
        props |= 1;
        break;
        
      case "LI":	
		/* Sets LI class to open to show sub nav */
		var c1 = (props & 1) ? 
          	       ((props & (2|4)) ? element.className = element.className ? element.className+" "+menu_open_class : menu_open_class : '')
				    			   
                 : ''; 	
				 	var c1 = (props & 1) ? 
          	       ((props & (2|4)) ? element.firstChild.className = element.firstChild.className ? element.firstChild.className+" "+menu_open_class : menu_open_class : '')
				    			   
                 : ''; 	
        break;
        
      case "A":
        if (props & 2) break; // once is enough
        var href = element.getAttribute("href");
			if (menu_isSameUrl(menu_url, href)) {
				props |= 4;
				element.className += " "+menu_active_class;
			}
        break;
	  }
    
    return props;
  }
  
  //matches two URIs when href is the last part of url
  //.. and . are correctly resolved
  function menu_isSameUrl(url, href) {
    var a = url.split(/[?\/]/i);
    var b = href.split(/[?\/]/i);
    var i = a.length - 1;
    var j = b.length - 1;
    while ((i >= 0) && (j >= 0)) {
      if (b[j] == "..") { j-=3; continue; }
      if (a[i] == "..") { i-=2; continue; }
      if ((b[j] == ".") || (b[j] == "")) { j--; continue; }
      if ((a[i] == ".") || (a[i] == "")) { i--; continue; }
      if (! (a[i] == b[j])) return false;
      i--;
      j--;
    }
    return true;
  }