var $j = jQuery.noConflict();


$j(document).ready(function(){
	
	
	$j("table.listTable > tbody > tr:even").addClass("rowAlt");
							
});



/*
	Fetches the path portion of a URL, e.g.
				
		input = http://localhost/about.us/board.of.trustees/trustee.profiles.shtml
		output = http://localhost/about.us/board.of.trustees/

*/
function getPathFromURL( url ) {

	return url.substr( 0, url.lastIndexOf( "/" )+1 );
}


/*
	Fetches the path portion of a URL, e.g.
				
		input = http://localhost/about.us/board.of.trustees/trustee.profiles.shtml
		output = http://localhost/about.us/board.of.trustees/

*/
function getStripParamFromURL( url ) {

	if( url.substr( 0, url.lastIndexOf( "?" ) ) != '' )
		return url.substr( 0, url.lastIndexOf( "?" ) );
	else
		return url;
}

/*
	The following is an override variable for the highlightMenuLink() function. To force
	 a menu item to be highlighted, set 'highlightMenuLinkOverride' equal to the EXACT
	 URL specified in the menu's <a href=> tag, e.g.:
	 
	 <script language='javascript'>highlightMenuLinkOverride = 'http://localhost/about.us/board.of.trustees/index.shtml';</script>
		
	 This SHOULD NOT BE DONE HERE -- place the override command anywhere in an editable region.
*/
var highlightMenuLinkOverride = null;

/*
	This function highlights a menu item using three different methods:
	
		1) If highlightMenuLinkOverride has been set to the exact URL (see above), this is used.
		2) An exact URL match is attempted (index pages MUST be named 'index.shtml')
		3) A directory name match is attempted
*/
function highlightMenuLink() {

	// make an alternate 'document.URL' that contains the default page name 'index.shtml'
	//  to make URL matching easier
	if( document.URL.lastIndexOf( '/' ) == document.URL.length-1 ) {
		var documentURL = document.URL.toLowerCase() + 'default.aspx';
	} else {
		var documentURL = document.URL.toLowerCase();
	}

	//
	// Pass #1: check for the override
	//
	if( highlightMenuLinkOverride != null ) {

		// loop through the links in the document
		for( var i=document.links.length-1; i >= 0; i-- ) {
			if( highlightMenuLinkOverride.toLowerCase() == document.links[i].href.toLowerCase() ) {
				document.links[i].className = 'secondaryNav secondaryNavSelect';
				break;
			}
		}				
		return;
	}

	//
	// Pass #2: loop through the links in the document, looking for an EXACT match
	//
	
	// strip the parameters
	docUrl = getStripParamFromURL( documentURL ).toLowerCase();
	
	for( var i = 0; i < document.links.length; i++ ) {
		
		// is this a 'secondaryNav' class link?
		if( document.links[i].className == 'secondaryNav' ) {
		
			// if the end of the href ends in a '#', skip it -- it's probably a test link that goes nowhere
			if( document.links[i].href.lastIndexOf( '#' ) == document.links[i].href.length-1 )
				continue;
		
			// append 'default.shtml' if the <a href=> ends in '/'
			if( document.links[i].href.lastIndexOf( '/' ) == document.links[i].href.length-1 ) {
				if( docUrl.toLowerCase() == document.links[i].href.toLowerCase() + 'default.aspx' ) {
					document.links[i].className = 'secondaryNavSelect';
					return;			
				}
			// otherwise, just compare em'			
			} else {
				if( docUrl.toLowerCase() == document.links[i].href.toLowerCase() ) {
					document.links[i].className = 'secondaryNavSelect';
					return;			
				}
			}
		}
	}
	
	//
	// Pass #3: if an exact match was not found, loop through and look for a directory match
	//
	
		// fetch the directory only
	docUrl = getPathFromURL( documentURL ).toLowerCase();

	for( var i=document.links.length-1; i >= 0; i-- ) {
		
		// if the end of the href ends in a '#', skip it -- it's probably a test link that goes nowhere
		if( document.links[i].href.lastIndexOf( '#' ) == document.links[i].href.length-1 )
				continue;
		
		// is this a 'menuLink' class link?
		if( document.links[i].className == 'secondaryNav' ) {
						
			s = getPathFromURL( document.links[i].href ).toLowerCase();		// strip the file
		
			if( s == docUrl ) {						// a match?			
				document.links[i].className = 'secondaryNavSelect';
				return;
			}
		}
	}
}
