/*
PURPOSE: Initialized the site menu, assigning an onclick event to each menu item which then performs the appropriate show/hide based on the menu item clicked
HISTORY:
12/21/10 cshang Genesis
01/04/11 cshang Modified to add fade effects
01/05/11 cshang Moved from the main index file to this file
*/
 $(document).ready(function(){
		$("#content").children().each (
			function(){
				$(this).hide();
			});
		//for each link of navMenu, hide the corresponding content and then set the active link and content
		$(".navMenu").each( 
		function(t){
				// oMenuLink is the UL object
				var oMenuLink=$(this);
				var sShow;
				// if the URL contains "sent" then it was redirected after the user filled out the contact form and hit Send
				if (location.hash.indexOf("sent") == 1) {
					//on page load, make the contact page (the last menu link) the active one
					// and display the confirm message
					$(oMenuLink).find("li:last").addClass("active");	
					// show the section that is referenced by the first link
					sShow = $(oMenuLink).find("li:last").find("a").attr("href");
					$("#contactform").hide(); // hide the contact form
					$("#contactconfirm").show(); // show the thank you confirm sent
				} else {
					//on page load, for the first LI, make it the active link
					$(oMenuLink).find("li:first").addClass("active");	
					// show the section that is refernced by the first link
					sShow = $(oMenuLink).find("li:first").find("a").attr("href");
				}
				$(sShow).show();	
				// for each link in the menu, add an onclick event
				$(oMenuLink).find("a").each(
					function(a){
						$(this).click(
							function(e){
								// prevent the default link so page does not reload
								e.preventDefault();
								// find the current active LI and remove the class
								$(oMenuLink).find("li.active").removeClass("active");
								$(this).parent().addClass("active");
								// hide all sections
								$("#content").children().hide();
								// hide the children before showing the section this link refers to so that we can perform some animation
								$($(this).attr("href")).children("#content-left").hide();
								$($(this).attr("href")).children("#content-right").hide();
								$("#contactform").show(); // reset the contact form to be shown onClick and the confirm to be hidden
								$("#contactconfirm").hide();
								// show the section
								$($(this).attr("href")).show();
								// fade in the text
								$($(this).attr("href")).children("#content-left").fadeIn("slow");
								$($(this).attr("href")).children("#content-right").show();
							}
						);
					}
				);
		});
						
 });

