/************************************************************************
 AUTOMATIC BREADCRUMB NAVIGATION
 ***********************************************************************/
/*
JavaScript can be used to display the breadcrumb trail on the current page. 
Once the code is added to the page, it will automatically determine the 
navigational trail for the breadcrumbs. Also, it won't need to be changed 
if the page is relocated in a different directory or on another server.
*/

function breadcrumbs(){
  sURL = new String;
  bits = new Object;
  var x = 0;
  var stop = 0;
  var output = "<a href=\"/\">Home</a>  >  ";
  sURL = location.href;
  sURL = sURL.slice(8,sURL.length);
  chunkStart = sURL.indexOf("/");
  sURL = sURL.slice(chunkStart+1,sURL.length)
  while(!stop){
    chunkStart = sURL.indexOf("/");
    if (chunkStart != -1){
      bits[x] = sURL.slice(0,chunkStart)
      sURL = sURL.slice(chunkStart+1,sURL.length);
    }else{
      stop = 1;
    }
    x++;
  }
  for(var i in bits){
    output += "<a href=\"";
    for(y=1;y<x-i;y++){
      output += "../";
    }
    output += bits[i] + "/\">" + bits[i] + "</a>  >  ";
  }
  document.write(output + document.title);
}

/************************************************************************
 SELF AWARE NAVIGATION
 ***********************************************************************/
/* 
This is a technique is for making my navigation bars “intelligent” or “self-aware.” 
By that, the navigation bar automatically knows which tab/button should be considered 
the currently active link, without having to manually specify a class or ID on either 
the body tag or on the links themselves.
*/

function setActive() {
  aObj = document.getElementById('nav').getElementsByTagName('a');
  for(i=0;i<aObj.length;i++) {
    if(document.location.href.indexOf(aObj[i].href)>=0) {
      aObj[i].className='active';
    }
  }
}
window.onload = setActive;
