/*
	metaNav.js
  controls display of metaNav navigation levels and descriptions
*/


/* add stylesheet which creates hide/show and other classes on the
   metaNav elements.  Users without Javascript will still be able 
   to see all style choices.  The no-javascript CSS file will be
   overridden by this new CSS file
*/

function setMetaNavStyle() {
  //sets metaNav stylesheet to the one used for javascript version
  metaNavStyle = cssQuery('#metanavStyleLink')[0];
  metaNavStyle.setAttribute('href','metanav.css');  
}

//register function to fire on window onload
registerPloneFunction(setMetaNavStyle);

function showNavLevel(level, id) {

  //display specified node at the specified level,
  //hide other nodes at that level.  levels defined by CSS classes

  selectedNode = cssQuery('#'+id)[0];
  allNodesAtLevel = cssQuery('.navLevel-'+level);
  for (node in allNodesAtLevel) {
    thisNode = allNodesAtLevel[node];
    if (thisNode == selectedNode) replaceClassName(thisNode, 'hide', 'show');
    else replaceClassName(thisNode  , 'show', 'hide');    
   }

   //hide all sublevels of the selected node
   subLevels = cssQuery('.navLevel-'+(level+1),selectedNode);
   for (node in subLevels) {
     thisNode = subLevels[node];
     replaceClassName(thisNode, 'show', 'hide');
   }
  
}

function showNavDescription(el) {
  var topLevelDescription = cssQuery('#topLevelDescription')[0];
  topLevelDescription.innerHTML = el.title;
}

function clearNavDescription(el) {
  var topLevelDescription = cssQuery('#topLevelDescription')[0];
  topLevelDescription.innerHTML = '';  
}

function clearNavLevel(id) {
  //hide specified nav level
  selectedNode = cssQuery('#'+id)[0];
  replaceClassName(selectedNode, 'show', 'hide')

  //hide all lower levels  
  allNodesAtLevel = cssQuery('.navLevel-3');
  for (node in allNodesAtLevel) {
    thisNode = allNodesAtLevel[node];
    replaceClassName(thisNode, 'show', 'hide');
   }
  
}