//PAGE CHANGE JAVASCRIPT
$(document).ready(function(){
	function loadContent(loadPageExt){
		$("#bg").fadeOut("1", function(){
			$("#loading").html("<br/><img src='Images/ajax-loader.gif'/>");
			$.ajax({
		  		url: loadPageExt,
		  		timeout: 5000,
		  		error: function (request, textStatus, errorThrown) {
		  			if(request.statusText=="OK"){
		  				alert("Timed Out! The page may be unavailable or could not be loaded at this time. Please refresh the page and try again.");
		  			}else if(request.statusText=="Not Found"){
		  				alert("Not Found! The page could not be loaded. Please refresh the page and try again.");
		  			}else{
	    				alert("Error Loading Page! "+page+" "+request.statusText+"");
	    			}
	    			$("#loading").html("");
	    			$("#bg").fadeIn("fast");
				},
			  		success: function(data){
		  			$("#loading").html("");
		    		$("#content").html(data);
		    		
		  			//update page nav
		  			$("#nav a").removeClass("current");
		  			changeNav = loadPageExt.split(".");
		  			changeNavId = "#nav #n_"+changeNav[0];
		  			$(changeNavId).addClass("current");
		  			
		  			$("#bg").fadeIn("fast");
		    		Cufon.replace('h1');Cufon.replace('h2');Cufon.replace('h5');//update titles with special font on page change
		  		}
			});
		});
		return false;
	}
	
	$(".jqueryNav a").live("click", function(){
		var page = $(this).attr("href");
		if(page=="/"){
			//home page selected
			loadPageExt="home.php";
			window.location.hash = "home";
		}else{
			loadPage = page.split("/");
			var loadPageExt = loadPage[1]+".php";
			window.location.hash = loadPage[1];
		}
		
		loadContent(loadPageExt);
		return false;
	});
});

