// ------------------------------------------------------------
// Generic helper functions. Replace these with the JS library
// du jour if the site starts getting laden with JS & AJAX...
// ------------------------------------------------------------

function $(id) {
	var el = (typeof id == 'string') ? document.getElementById(id) : id;
	return el;
}

function addEvent(element, eventType, newEvent) {
	var el = $(element);
	if (typeof el['on'+eventType] != 'function') {
		el['on'+eventType] = newEvent;
	} else {
		var oldEvent = el['on'+eventType];
		el['on'+eventType] = function() {
			oldEvent();
			newEvent();
		}
	}
}

function addLoadEvent(newEvent) {
	addEvent(window,'load',newEvent);
}


// ------------------------------------------------------------
// Rollover stuff for the main nav and section intro paragraphs
// ------------------------------------------------------------

function navRollOver() {
	var el = $('nav-rollover').childNodes[0];
	if (el) {
		el.oldClassName = el.className;
		el.className = this.className;
	}
}

function navRollOut() {
	var el = $('nav-rollover').childNodes[0];
	if (el) el.className = el.oldClassName;
}

function initNavRollOvers() {
	var nav = $('navigation');
	if (nav) {
		var links = nav.getElementsByTagName('li');
		for (var i=0; i<links.length; i++) {
			links[i].onmouseover = navRollOver;
			links[i].onmouseout = navRollOut;
			links[i].onfocus = function(){ this.blur(); }
		}
	}
}

addLoadEvent(initNavRollOvers);
