// Javascript Function 
(function($){ 


$.fn.sideNav = function(title, file, sideMenuFile) {
	//sometimes a link's click event gets to execute more than once
	//the second click sends an empty file i.e home page
	//alert(file);

	if(file=="") {return;} //to stop that homepage from happening 
	
	//$(this).click(function () {
							  
		//alert("Title: " + title + " File:"+file);					
		// change the title
		$("span#menuHeaders").html(title);
					
		// Empty the content div
		$("#content").html("");
		
		// Reveal the menu and cotent area
		$('div#menu,div#content').slideDown('slow', function () {
												  
			// add new content
			$.ajax({ 
			  url: file,
			  cache: false,
			  success: function(html){ 
			  	$("#content").html("");
				$("#content").html(html);
				

				
				$(".menu_nav_links").bind("click", function (e) {
																			  
					$("a#" + this.id).sideNav($(this).text(),this.href,sideMenuFile);
					//window.location.hash = linkId;
					 $("a#" + this.id).removeAttr('href');
					e.preventDefault();
					 return false;
		
     			});
				
			  }
			});		
			
			
			// add new side menu
			$.ajax({ 
			  url: sideMenuFile,
			  cache: false,
			  success: function(html){ 
			  	$("#sideNavigation").html("");
				$("#sideNavigation").html(html); 
					$(".menu_nav_links").bind("click", function (e) {
					$("a#" + this.id).sideNav($(this).text(),this.href,sideMenuFile);
					 $("a#" + this.id).removeAttr('href');
					 e.preventDefault();
					 return false;
     			});

			  },
			  
			  error: function () { return false; }
			
			
												  
		});


		});
	
	return this;

//});

}

})(jQuery); 
