  // Source Code for Outlining
  // Alex Fung Dec 1998
  // at http://alexfung.fly.to/js/outline.js
  //  modified Jul 2000 to 
  //    double click body to hide, single click body now is ignored
  //      As a result, you can now select/hilite body text
  //        without the whole paragraph suddenly disappears
  //      However you still flips the display status when you 
  //        select section headings.
  //    use one single function for click and double click
  //    use one single function for mouseover and mouseout

  if (document.all) {
    document.styleSheets["outline"].addRule("UL UL","display:none");
    //  UL UL {display: none}
    if (window.DaisyChain) window.DaisyChain.add("load", doOutlineLoad);
    else window.onload = doOutlineLoad;
  }

  // see if a parent of src has tag dest
  function checkParent(src, dest) {
    while (src!=null) {
      if (src.tagName == dest) return src;
      src = src.parentElement;
    }
    return null;
  }

  // see if srcel is parent of a UL 
  function outUL(srcel) {
    var pos = srcel.sourceIndex+1;
    var da = document.all;
    var dal = da.length;
    if (pos >= dal) return null;
    while (srcel.contains(da[pos])) {
      if ("UL"==da[pos].tagName) return da[pos];
      if (++pos >= dal) break;
    }
    return null;
  }


  function outline() {     
    var srcel = checkParent(event.srcElement, "LI");
    if (null==srcel) return;

    var el = outUL(srcel);
    if (el==null) return;
    
//  outUL returns null if tagName is not UL, so recheck not needed
    if (""==el.style.display) {
      el.style.display = "block"
      srcel.className = "open"
    } else {
      el.style.display = ""
      srcel.className = "parent"
    }
    event.cancelBubble = true;
  }

  function outover() {     
    var srcel = checkParent(event.srcElement, "LI");
    if (null==srcel) return;
    var el = outUL(srcel);
    if (el==null) return;
    if (el.contains(event.srcElement)) return;
    // it is annoying that empty spaces belongs to the parent
    srcel.style.color = event.type == 'mouseover' ? "red" : "navy";
    event.cancelBubble = true;
  }

 function doOutlineLoad() {
    // Do Loading
    if (window.DaisyChain) {
      window.DaisyChain.add("mouseover", outover);
      window.DaisyChain.add("mouseout", outover);
      window.DaisyChain.add("click", outline);
    } else {
      document.onclick = outline;
      document.onmouseover = outover;    
      document.onmouseout = outover;
    }
  }

