// highlight current page in right nav

// extract the file name from a URL 
//(if input is '/files/index.html', output is 'index')
function extractPageName(hrefString)
{
  var arr = hrefString.split('.');
  arr = arr[arr.length-2].split('/');
  return arr[arr.length-1].toLowerCase();		
}

// search through all the links in array, if one points to
// the same file, apply the class .selected to it and to its 
// parent
function setActiveMenu(arr, crtPage)
{
  for(var i=0; i < arr.length; i++)
  if(extractPageName(arr[i].href) == crtPage)
  {
    arr[i].className = 'selected';
    arr[i].parentNode.className = 'selected';
  }
}

// call this method from your page
function setPage()
{
  if(document.location.href) 
    hrefString = document.location.href;
      else
    hrefString = document.location;

    if (document.getElementById('side-nav')!=null)
    setActiveMenu(document.getElementById('side-nav').getElementsByTagName('a').extractPageName(hrefString));
}

window.onload=setPage;

var hasquestion=hrefString.indexOf('?');
if (hasquestion == '-1')
{
arr = arr[arr.length-2].split('/');
return arr[arr.length-1].toLowerCase();
}
else
{
return arr[arr.length-1].toLowerCase();
}
}

