/* - navHighlight.js -
*	
*	provides routines to automatically highlight
*	portions of the section, side, and tab 
*	navigation menus
*
*	links the direct edit button appropriately
*/

$(document).ready(function() {
	var uri = window.location+'';
	uri = uri.replace(/%2F/gi, '/');
	var filename = uri.substr(uri.lastIndexOf('/')+1, uri.lastIndexOf('.')-uri.lastIndexOf('/'));

	// highlight tab nav
	$('ul#pageTab a').each(function() {
		var thisURI = $(this).attr('href');
		var thisFilename = thisURI.substr(thisURI.lastIndexOf('/')+1, thisURI.lastIndexOf('.')-thisURI.lastIndexOf('/'));		
		if(thisFilename === filename)
			$(this).attr('id', 'on');			
	});

	// highlight side nav
	var subsectionHomeURI = $('ul#pageTab a:first').attr('href');
	$('ul.mlist a').each(function() {
		if ($(this).attr('href') === subsectionHomeURI)
			$(this).attr('id', 'selected');
	});

	// guard against empty subsection headings
	$('#local_nav ul.mlist').each(function() {
		if ($(this).find('a').length == 0)
			$(this).add($(this).prev('span')).add($(this).next('br')).remove();
	});

	// highlight top nav
	var sectionURI = uri.substr(uri.indexOf('edu/')+4, uri.length);
	sectionURI = '/'+sectionURI.substr(0, sectionURI.indexOf('/'));
	$('ul#navlist a').each(function() {
		if ($(this).attr('href') === sectionURI)
			$(this).attr('id', 'current');			
	});

});

