/* Simple recursing script to highlight appropriate items in left hand nav */
var hireNav = {
nav_id: 'leftNav', // SET THIS - this is the id of your topmost <ul>
displayLoop: function(el) {
// set the link LI itself

el.className = 'menuOn';

el.parentNode.style.display = 'block';
// if this <li> has a child ul specifically in it
var neighbour = el.childNodes;
for (var i=0; i<neighbour.length; i++){
if (neighbour[i].nodeName == 'UL') {
neighbour[i].style.display = 'block';
}
}
// carry on up the tree
var parEl = el.parentNode.parentNode;
if (parEl.nodeName == 'LI') {
this.displayLoop(parEl);
}
},
// initialise
init: function() {
// get the LH nav:
var nav = document.getElementById(this.nav_id);
// first collapse all child ul items
var childEls = nav.getElementsByTagName('ul');
for (var i=0; i<childEls.length; i++){
childEls[i].style.display = 'none'; 
}
// nav_override can be used to 'cheat' - use it in an html page, ie: var nav_override = "not_my_filename.html";
if (typeof(nav_override)!="undefined") {
// if "override" is set in the html page, that's our "loc" var
var loc = nav_override;
} else {
// get the current location as string
var loc = String(window.self.location);
loc = loc.toLowerCase();
// get the text from the last '/'
locArr = loc.split('/');
loc = locArr[locArr.length -1];
}
// loop through all the links till we find the correct one:
var linksArr = nav.getElementsByTagName('a');
var currLink = '';
for (var i=0; i<linksArr.length; i++) {
//currLink = linksArr[i].getProperty('href');
currLink = linksArr[i].getAttribute('href');
currLink = currLink.toLowerCase();
if (currLink.search(/\//) != -1) {
var currSplit = currLink.split('/');
currLink = currSplit[currSplit.length -1];
}
// currLink ends up as a lowercase string filename - ie 'this.html'
if (loc == currLink) {
// check for a parent element:
this.displayLoop(linksArr[i].parentNode); // send this <li> up
}
}
}
}
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
if (oldonload) {
oldonload();
}
func();
}
}
}
addLoadEvent(function() {
hireNav.init();
});
