// JavaScript Document
function makeCollapsible(listElement){

  // removed list item styles
  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){
      // build a list of child ol and ul elements and hide them
      var list=new Array();
      var grandchild=child.firstChild;
      if (grandchild == findParent(document.location,'')) {
        grandchild.style.background='#647C8D url(/psych/css/images/custom_bullet.gif) no-repeat 7px center';
        grandchild.style.color = '#E9DE3C';
      }
      
      while (grandchild!=null){
        
        if (grandchild.tagName=='OL' || grandchild.tagName=='UL'){
          if (child.firstChild == findParent(document.location,'')) {
            grandchild.style.display='block'; 
            grandchild.style.backgroundColor='#96A6B1';
            grandchild.style.textIndent = '12px';
          }
          else{
            grandchild.style.display='none';
          }          
          list.push(grandchild);
          var c=grandchild.firstChild;
          while (c!=null){
            if(c.firstChild==String(document.location) || c.firstChild==findFirstParent(String(document.location), '')){
              //c.firstChild.style.background='url(/psych/css/images/custom_bullet.gif) no-repeat 7px center';
              c.firstChild.style.color='#E9DE3C';
              child.firstChild.style.background='#647C8D url(/psych/css/images/custom_bullet.gif) no-repeat 7px center';
            }
            c=c.nextSibling;
          }
        }
        grandchild=grandchild.nextSibling;
      }
      
    }
    child=child.nextSibling;
  }
}

function findFirstParent(childPage, homePage) {
  childPage = new String(childPage);
  homeLocation = childPage.indexOf(homePage);
  if (homeLocation >= 0) {
    p = childPage.slice(homeLocation);
    slashLoc = p.lastIndexOf("/");
    if (slashLoc > 0) {
      p = p.slice(0, slashLoc+1);
    }
    else{
      p = "";
    }
  }
  else{
    p = "";
  }
  return p;
}

function findParent(childPage, homePage) {
  childPage = new String(childPage);
  homeLocation = childPage.indexOf(homePage);
  if (homeLocation >= 0){
    parentPage = childPage.slice(homeLocation);
    
    e=parentPage.split('/');
    parentPage =  e.slice(0,7).join('/'); 
    
    slashLoc = parentPage.lastIndexOf("/");
    if (slashLoc > 0) {
      parentPage = parentPage.slice(0, slashLoc+1);
    }
    else{
      parentPage = "";
    }
  }
  else{
    parentPage = "";
  }
  return parentPage;
}