/* 
  So this script should:
	1. Get all the classes on the body tag
	2. Match an element id with the class name
	3. Change the class of the anchor tag inside the tag 
	   with that element id to "normal"
	4. If there's a UL within that element id, then look for
	   the UL with id="tertiarynav" and make it visible
*/
function setStyles() {
	d = document;
	
	// turn off the tertiarynav until we need it	
	elements = d.getElementsByTagName('ul');
	for (x = 0; x < elements.length; x++) {
		if (elements[x].id.indexOf('tertiarynav') != -1) {
			elements[x].style.display = 'none';
		}
	}
	// Grab all the classes from the body tag and put 'em in a string
	classes = d.body.className;
	
	/*
	  Strip any leading or trailing spaces. Should probably look
	  for \n,\r and tab, too.
	*/
	classes = (classes.replace(/^\W+/,'')).replace(/\W+$/,'');
	
	// Throw it all into an array
	classArray = classes.split(' ');

	/* 
	  Loop through the specified classes and match it with an ID. 
	  Check if the ID has a childNode with an id of teritiarynav,
	  and if so, make it visible.
	*/
	for (x = 0; x < classArray.length; x++) {
		if (d.getElementById(classArray[x])) {
			li = d.getElementById(classArray[x]);
			ul = li.getElementsByTagName('ul');
			for (y = 0; y < ul.length; y++) {
				if (ul[y].id.indexOf('tertiarynav') != -1) {
					ul[y].style.display = 'block';
				}
			}
		}
	}

	/*
	  Set the styles on the first and last elements in the class
	  to look "normal", indicating current page in the hierarchy.
	*/
	if (d.getElementById(classArray[0])) {
		d.getElementById(classArray[0]).getElementsByTagName("a").item(0).className = 'normal';
	}
	if (d.getElementById(classArray[classArray.length-1])) {
		d.getElementById(classArray[classArray.length-1]).getElementsByTagName("a").item(0).className = 'normal';
	}
}
window.onload = function() {
	setStyles();
}

