/* Author: Jason Gennaro
	Oct. 18, 2010
	modified on Apr. 20, 2011
	
	Script does two things
	1. opens and closes sub navigation depending on section (determined by folder name) 
	2. toggles top level nav elements
	
	contains function within an object
	to ensure that it does not conflict with
	other javascript
*/

var LeftNavOpenShut = 
	{
		init: function()
			{
				//ensures all sub navs are closed
				$('#justice-ont-menu, #courts-menu, #ovss-menu, #family-menu, #pgt-menu, #jot-menu').hide();				
				
				//gets local file path 
				var leftNavPathNames = location.pathname;
				//divides local file path according to folders
				var folderToHighlight = leftNavPathNames.split("/");
				//checks first high level folder (3rd element in array) and 
				//matches to menu, then toggles open
				switch(folderToHighlight[2])
					{
						case "justice-ont":
							$('#justice-ont-menu').show();
						break;
						case "courts":
							$('#courts-menu').show();	
						break;
						case "ovss":
							$('#ovss-menu').show();	
						break;
						case "family":
							$('#family-menu').show();
						break;
						case "pgt":
							$('#pgt-menu').show();
						break;
						case "jot":
							$('#jot-menu').show();
						break;						
						default:
							$('#justice-ont-menu').show();
						break;
					}

				//pgt is on main nav but is a second level folder (under family)
				//therefore needed to check next element in array
				//also needed to close family item that is open w above case statement					
				if (folderToHighlight[3] == "pgt")
					{
						$('#family-menu').hide();
						$('#pgt-menu').show();
					}		

				//these other top level nav items remain closed until clicked, then toggle open					
				$('ul.exploreGovernment').hide(); 
 				$('ul.leftContacts').hide(); 
				$('ul#socialmenu').show();

				//if on the contact page (found the word in the path) then open the Contact section
				if(leftNavPathNames.indexOf("contact") != -1){
					$('ul.leftContacts').show();
					}			
	

				$('.header').click(
					function(){
					$(this).next('ul.menu').slideToggle("slow");
					return false; 
					//need to return to false to shut off default result
					//which is click event that refreshes page and bounces user to top 
					});
					
			}
	};

$(document).ready(function(){LeftNavOpenShut.init();});
