/* Simple script to highlight appropriate items in left hand nav within flat hire section */
/* DEPENDENCIES: mootools.js */
var hireNav = {
	// initialise
	init: function() {
		// get the LH nav:
		var nav = $('hireLeftNav');
		// first collapse all child ul items
		var childEls = nav.getElements('ul');
		childEls.each(function(child) {
			child.setStyle('display', 'none');
		});
		
		// get the current location as string
		var loc = String(window.self.location);
		loc = loc.toLowerCase();
		// this returns the full url, so we need to 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.getElements('a');
		var currLink = '';
		for (var i=0; i<linksArr.length; i++) {
			currLink = linksArr[i].getProperty('href');
			currLink = currLink.toLowerCase();
			/* Moz difference... SEARCH for '/' character to see if a full link is returned, or a relative one... */
			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) {
				// does our current list have a parent <li> ? If so the path would be: here <a> --> parent <li> --> parent <ul> --> parent <li>
				var parEl = linksArr[i].parentNode.parentNode.parentNode;
				if (parEl.nodeName == 'LI') {
					// case 1: parents exist, we're in a child page
					// set the parEl class:
					parEl.className = 'currentPage';
					// set the link LI itself
					linksArr[i].parentNode.className = 'currentPage';
					// make sure the child is shown:
					//linksArr[i].parentNode.parentNode.setStyle('display', 'block');
					linksArr[i].parentNode.parentNode.style.display = 'block';
					break;
				} else {
					// case 2: no parents, we're in a top-level page
					linksArr[i].parentNode.className = 'currentPage';
					// make sure any child <ul> is shown
					var childEls = linksArr[i].parentNode.getElementsByTagName('ul');
					if (childEls.length == 1) {
						childEls[0].style.display = 'block';
					}
					break;
				}
			}
		}
	}
}
/* Moo DomReady Event makes initial function calls */
window.addEvent('domready', function() {
	if ($('hireLeftNav')) {
		hireNav.init();
	}
});