//
// MenuHighlight - menuhighlight.js
// Adam Mark Finlayson, WTS
// amf%northwestern!edu
//
// Dependencies:
//     URL.js - v0.X
//

// -------------------------------------------------
// function addHighlight(idToSearch, highlightClass)
//
// Applies a style to links matching the current URL
// Used to simulate the "current page" feeling in navigation
//
// Logic:
//     Goes through each anchor (<a> tag) in a given [idToSearch]
//     If the anchor matches this document's URL, apply the [highlightClass] style
//
// Variables:
//     idToSearch = what id to look in
//     highlightClass = the class to apply to matching anchors
//
// Returns: void
//
// Notes:
//     * The [highlightClass] has to be defined in the CSS (obviously)
//     * Does not remove the <a> itself (i.e., still a link, just looks different)
//     * Only searchs by id, not class, HTML tag, or any other mechanism
//
function addHighlight(idToSearch, highlightClass) {
	if(!document.getElementById) return ;							// browser detect DOM support
	
	var url = newURLFromLocationAndDocument(location, document) ;	// the URL of this document
	
		// get the container we should be searching
	var container = document.getElementById(idToSearch) ;			// get the container
	if(container==null) return;										// bail if we can't find it
	
	var anchors = container.getElementsByTagName("a") ;				// get all anchors
	for(i=0; i<anchors.length; i++) {								// iterate anchors...
		var linkCandidate = anchors.item(i) ;							// this candidate
		var candidateHREF = linkCandidate.getAttribute("href") ;		// get the href
		var joinedHREF = url.joinHREF(candidateHREF) ;					// relative to this URL
		if(url.equalsHREF(joinedHREF)) {								// if equal...
			linkCandidate.className = highlightClass ;					// set the class
		}																// ...if equal
	}																//...iterate anchors
}


