/* Adds color toggling behavior to the department table on the home page */
/* Requires Prototype 1.4.0+ */

function toggleColor (color, classes) {
	if (color == 'dark') { classes.remove ('dark'); classes.add ('light'); }
	else if (color == 'light') { classes.remove ('light'); classes.add ('dark'); }
}

function invertRow () {
	// parent of parent is the TR element
	var myrow = this.parentNode.parentNode;
	// get both TDs in an Enumerable object
	var cells = $A(myrow.getElementsByTagName('td'));
	// for each TD,
	cells.each( function (td) {
		// get its list of classes,
		var classes = Element.classNames(td);
		// and for each one, toggle it if necessary
		classes.each( function (color) { toggleColor (color, classes); } );
	} );
}

function assignDeptListRowBehavior () {
	// #deptlist is the TABLE element
	// get all anchors contained within it, and for each one,
	$A($('deptlist').getElementsByTagName('a')).each( function (obj) {
		// assign behavior to mouse hover events
		obj.onmouseover = invertRow;
		obj.onmouseout = invertRow;
	});
}

// On document load, attach department list behavior
Event.observe(window, 'load', assignDeptListRowBehavior, false);
