/*
expander_setup():
      Provides a way to toggle the display style (i.e. collapse and
      expand) an element.

      parentId - id attribute of an element under which we search for
      controls.

      controlClass - the class name that identifies a control. Must
      refer to an 'a' element. It should have a single child node of
      value '+' or '-' to start with. e.g. <a href='#'>-</a>

      The target element for a control (the one that gets its
      display toggled) is identified by an id attribute formed by
      appending '_target' to the id of its control element.

      Example usage:
      window.onload=function() {expander_setup('toc_container','expander') };
*/


function expander_setup(parentId, controlClass) { 
    function install(elt) {
	if (elt.nodeName.toLowerCase() != "a") {
	    return;
	}
	var cls = elt.className;
	if (! cls || cls != controlClass)
	    return;
	target=document.getElementById(elt.id + "_target");
	if (target) {
	    textNode=elt.childNodes[0];
	    elt.toggleTarget=target;
	    elt.toggleSym=textNode;
	    elt.onclick = function() {
		toggle(this);
	    }
	    elt.href = "javascript:void(0);";
	    /* set initial state - collapse if we need to*/
	    if (textNode.nodeValue=="+")
		target.style.display = "none" ;
	}
    }

  function toggle(a) { 
      if (a.toggleSym.nodeValue == '+') {
	  a.toggleSym.nodeValue ='-';
	  a.toggleTarget.style.display="";
      } else {
	  a.toggleSym.nodeValue ='+';
	  a.toggleTarget.style.display="none";
      }
  }

  function walk(elt) {
    if (! elt || elt.nodeType != 1) {
      return;
    }
    install(elt);
    var i;
    for (i = 0; i < elt.childNodes.length; i++) {
      walk(elt.childNodes[i]);
    }
  }

  var parentElt = document.getElementById(parentId);
  if (! parentElt) {
    return;
  }
  walk(parentElt);
}


