/*
 * sfActive uses the active menu trail (retrieved from the breadcrumb) to
 * highlight the same menu items in the header navigation menu and the left
 * sidebar navigation menu
 */ 

sfActive = function() {
	
	// grab the active menu trail from the breadcrumb
	if (document.getElementById("bread")) {
		var breadEls = document.getElementById("bread").getElementsByTagName("A");
	} else {
		var breadEls = [];
	}
	
	// grab all the links from header-nav
	var sfEls = document.getElementById("block-menu-55").getElementsByTagName("A");
	
	// grab all the links from sidebar-left
	var sbEls = document.getElementById("block-menu-115").getElementsByTagName("A");
	
	/*
		iterate over the items in header-nav
			if an item in header-nav matches an item in the breadcrumb, then highlight
			that item using the CSS class 'active'
	*/
		
	// mark active links in header nav
	for (var i=0; i<sfEls.length; i++) {
		if (sfEls[i].className != "active") {
			for (var j=0; j<breadEls.length; j++) {
				if (sfEls[i].href == breadEls[j].href) {
					sfEls[i].className+=" active";
					if (sfEls[i].parentNode.nodeName == "LI") {
						sfEls[i].parentNode.className+=" active";
					}
				}
			}
		}
	}
	
	// mark active links in sidebar nav
	for (var i=0; i<sbEls.length; i++) {
		if (sbEls[i].className != "active") {
			for (var j=0; j<breadEls.length; j++) {
				if (sbEls[i].href == breadEls[j].href) {
					sbEls[i].className+=" active";
				}
			}
		} else if (sbEls[i].parentNode.nodeName == "LI") {
				sbEls[i].parentNode.className+=" active";
		}
	}
}
