// JavaScript Document
$(document).ready(function(){
   // initial hide of UL UL in main nav
   $("div#navmain ul li ul:not(.dontHide)").hide();
   // unhide any UL UL specifically not hidden
   $("div#navmain ul li ul.dontHide").show().parent().addClass("expanded");   
   // check for UL UL, and assign class
	$("div#navmain ul ul").parent().addClass("hasSub").children("a").addClass("hasSubA");   
   // on hover, displays submenu, on unhover hides
   var $expander = '<a class="expandSection" href="#" title="Expand this section">&nbsp;</a>';
   var $closer = '<a class="closeSection" href="#" title="Close this section">&nbsp;</a>';
   $("div#navmain ul li.hasSub:not(.expanded)").prepend($expander);
   $("div#navmain ul li.expanded").prepend($closer);
   // toggle click when already expanded section has been applied
   $("div#navmain a.expandSection").toggle(
		function() { 
			$(this).attr('title', 'Close this section').next().next().slideDown(700).parent().addClass("expanded"); 
			$(this).removeClass("expandSection").addClass("closeSection");
		},
		function() { 
			$(this).attr('title', 'Expand this section').next().next().slideUp(500).parent().removeClass("expanded"); 
			$(this).removeClass("closeSection").addClass("expandSection");
		}
	);
   // toggle click when already closed section has been applied
   $("div#navmain a.closeSection").toggle(
		function() { 
			$(this).attr('title', 'Expand this section').next().next().slideUp(500).parent().removeClass("expanded");
			$(this).removeClass("closeSection").addClass("expandSection");
		},
		function() { 
			$(this).attr('title', 'Close this section').next().next().slideDown(700).parent().addClass("expanded");
			$(this).removeClass("expandSection").addClass("closeSection");
		} 
	);
	// collapse left nav on sitemap page
	$("body.sitemap div#navmain ul li ul.dontHide").hide();   
 });