<!--
// Collapsible list code and images from
// http://www.safalra.com/programming/javascript/collapsible-lists/

/* CLOSED_IMAGE - the image to be displayed when the sublists are closed
 * OPEN_IMAGE   - the image to be displayed when the sublists are opened
 */
CLOSED_IMAGE='/sites/all/themes/qmul/plus.png';
OPEN_IMAGE='/sites/all/themes/qmul/minus.png';

/* makeCollapsible - makes a list have collapsible sublists
 *
 * listElement - the element representing the list to make collapsible
 */
function makeCollapsible(listElement){

  // Remove list item bullets and the space they occupy:
  listElement.style.listStyle='none';
  listElement.style.marginLeft='0';
  listElement.style.paddingLeft='0';

  // Loop over all child elements of the list:
  var child=listElement.firstChild;
  while (child!=null){

    // Only process li elements (and not text elements):
    if (child.nodeType==1){

  child.style.backgroundImage='none';
      // Build a list of child ol and ul elements and hide them:
      var list=new Array();
      var grandchild=child.firstChild;
      while (grandchild!=null){
        if (grandchild.tagName=='OL' || grandchild.tagName=='UL'){
          grandchild.style.display='none';
          list.push(grandchild);
        }
        grandchild=grandchild.nextSibling;
      }

      // Add toggle buttons:
      var node=document.createElement('img');
      node.setAttribute('src',CLOSED_IMAGE);
      node.setAttribute('class','collapsibleClosed');
      node.onclick=createToggleFunction(node,list);
      child.insertBefore(node,child.firstChild);

    }
    child=child.nextSibling;
  }
}

/* createToggleFunction - returns a function that toggles the sublist display
 *
 * toggleElement  - the element representing the toggle gadget
 * sublistElement - an array of elements representing the sublists that should
 *                  be opened or closed when the toggle gadget is clicked
 */
function createToggleFunction(toggleElement,sublistElements){

  return function(){

    // Toggle status of toggle gadget:
    if (toggleElement.getAttribute('class')=='collapsibleClosed'){
      toggleElement.setAttribute('class','collapsibleOpen');
      toggleElement.setAttribute('src',OPEN_IMAGE);
    }else{
      toggleElement.setAttribute('class','collapsibleClosed');
      toggleElement.setAttribute('src',CLOSED_IMAGE);
    }

    // Toggle display of sublists:
    for (var i=0;i<sublistElements.length;i++){
      sublistElements[i].style.display=
          (sublistElements[i].style.display=='block')?'none':'block';
    }
  }
}
// Needs <body onload="makeCollapsible(document.getElementById('collapsiblelist'));">
-->


