/**
 * @author Justin Johnson
 * @version 0.0.1a 20071017 JJ
 */

ol = window.onload;
window.onload = function() {
	ol;

	var element   = document.getElementById('pathhighlighter'),
		nodes     = element.childNodes,
		className = element.className.match(/phl-class-([a-z_\-0-9]*)/i),
		path      = window.location.toString().match(new RegExp(".*://[^/]*/([^/]*).*")),
		n         = null,
		i         = 0;
		
	className = className[1] ? className[1]          : 'pathhighlight';
	path      = path[1]      ? path[1].toLowerCase() : '[home]';

	for ( ; i<nodes.length; i++ ) {
		n = pathhighlighter_findrel(nodes[i]);
		if ( n ) {
			if ( n.rel.toLowerCase() == path ) {
				n.className = className;
			}
			else if ( n.className.indexOf(className) != -1 ) {
				n.className = n.className.replace(className, '');
			}
		}
	}
}

pathhighlighter_findrel = function(node) {
	if ( node.rel ) {
		return node;
	}
	else {
		var children = node.childNodes, i=0;
		
		for ( ; i<children.length; i++ ) {
			if ( (node = pathhighlighter_findrel(children[i])) ) {
				return node;
			}
		}
	}
	return false;
}