 $(document).ready(function() {
  
    var found_page = false;
    var last_id = null;
    var img_root = '/images/';
   
	// Get path from browser
	var my_path = window.location.pathname;

	jQuery.each($('img.navbar'), function(i, obj) {
			
		// check to see if the main item is the active url

		var img_href = obj.parentNode.href;

		// Set the links active or not (match end of href string)
		if (img_href.indexOf(my_path) == (img_href.length - my_path.length) )
		{
			//$('div#' + obj.id).css('background-image', 'url(' + img_root + obj.id + '_ovr.jpg)');
			$('img#' + obj.id).attr('src', img_root + obj.id + '_ovr.jpg');
			last_id = obj.id;
		}
		else
			//$('div#' + obj.id).css('background-image', 'url(' + img_root + obj.id + '_slice.gif)');
			$('img#' + obj.id).attr('src', img_root + obj.id + '_slice.gif');
			
		// check to see if this is the active page too
		// still have to search sub children even if we match the top, because sub item can have same link as top
		if (!found_page)
		{
			// First search the sub-links
			jQuery.each( $('ul#' + obj.id).children('li').children('a'), function (i, obj) {
				
				// Match end of href string to current url
				if (obj.href.indexOf(my_path) == (obj.href.length - my_path.length) )
				{

					var my_li = obj.parentNode;
					var my_ul = my_li.parentNode;
					
					obj.className = 'active';
					my_li.className = 'active';
					
					// jQuery method doesn't mess up the formatting overrides
					$('ul.subnav#' + my_ul.id).show();
					//my_ul.style.display = 'inline';
					
					// Next, highlight the section
					//$('div#' + my_ul.id).css('background-image', 'url(' + img_root + my_ul.id + '_ovr.jpg)');
					$('img#' + my_ul.id).attr('src', img_root + my_ul.id+ '_ovr.jpg');

					// Finally set the necessary other globals
					last_id = my_ul.id;
					found = true;
					
				}
	
			});
		
			
		}
			
		// Now set the mouseovers for each navbar item	
			
		$('a#' + obj.id).mouseover(function() {
			
			var new_id = $(this).attr('id');		
			
			if (last_id != new_id)
			{
				if (last_id)
				{
					//$('div#' + last_id).css('background-image', 'url(' + img_root +last_id + '_slice.gif)');
					$('img#' + last_id).attr('src', img_root + last_id + '_slice.gif');
					$('ul.subnav#' + last_id).hide();
				}
					
				//$('div#' + new_id).css('background-image', 'url(' + img_root + new_id + '_ovr.jpg)');
				$('img#' + new_id).attr('src', img_root + new_id + '_ovr.jpg');
				
				$('ul.subnav#' + new_id).show();
				last_id = new_id;
				
			}
			
			
	   	});

	
	});
    

});


