$(document).ready(function() {
						   
	var hash = window.location.hash.substr(1);
	var href = $('#nav li a').each(function(){
		var href = $(this).attr('href');
		if(hash==href.substr(0,href.length-5)){
			var toLoad = hash+'.html #content';
			$('#content').load(toLoad)
		}											
	});

	$('#nav li a').click(function(){
								  
		var toLoad = $(this).attr('href')+' #content';
		$('#content').fadeOut('fast',loadContent);
		$('#load').remove();
		$('#wrapper').append('<span id="load">LOADING...</span>');
		$('#load').fadeIn('fast');
		window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
		function loadContent() {
			$('#content').load(toLoad,'',showNewContent())
		}
		function showNewContent() {
			$('#content').fadeIn('fast',hideLoader());
		}
		function hideLoader() {
			$('#load').fadeOut('fast');
		}
		return false;
		
	});

	//Control highlighting of navigation
	
	$('#nav li.japrofile a').click(function(){
		$("#nav li.japrofile").addClass("nav-selected");
		$("#nav li.jacomments").removeClass("nav-selected");
		$("#nav li.jagallery").removeClass("nav-selected");
		$("#nav li.jaextratab").removeClass("nav-selected");
	});
	
	$('#nav li.jacomments a').click(function(){
		$("#nav li.japrofile").removeClass("nav-selected");
		$("#nav li.jacomments").addClass("nav-selected");
		$("#nav li.jagallery").removeClass("nav-selected");
		$("#nav li.jaextratab").removeClass("nav-selected");
	});
	
	$('#nav li.jagallery a').click(function(){
		$("#nav li.japrofile").removeClass("nav-selected");
		$("#nav li.jacomments").removeClass("nav-selected");
		$("#nav li.jagallery").addClass("nav-selected");
		$("#nav li.jaextratab").removeClass("nav-selected");
	});

});