// ====================================================================================
// ANALYZE THE URL
// ====================================================================================		
	
	var hash = window.location.hash;
	var pathname = window.location.pathname;
	
	/// if there is a pathname AND a hash (an edge case) redirect to pathname only
	if( hash != '' && pathname.length > 2 ) { location.href = 'http://jeanninehebb.com' + pathname; }
	
	/// if there is only a hash, the home content should be hidden while hash content is loaded
	var hideHome = false;
	if( hash != '' ){ 
		hideHome = true;
	}
	else {
		if(pathname === '/'){ 
			/// nuthin
		 }			
			else {
				location.href = '/#' + pathname;
			}
		}	

		

// ====================================================================================
// Hash history
// ====================================================================================	
		
	function loadContent(hash){
		/// EXCEPTION: IF NO HASH THEN LOAD HOME
		if(hash == ""){ hash = "home";}
		hash = hash.replace("#/", "");
		var cns = changeNavState(hash);
		$("#loading").fadeIn();
		$("#content").fadeOut('slow', function(){
			$("#content").load(hash+".php", function(){
				$("#content").fadeIn();
				$("#loading").fadeOut();				
				$("body").removeClass("waiting");
			});
		});	
	}

	function changeHash(hash){
		location.hash = hash;
	}
	
	function changeNavState(hash){
		$("#nav a").removeClass("on");
		$("#nav a."+hash).addClass("on");
	}

	var currHash = "";
	function checkHash(){
		/// if url hash doesn't equal current hash then change things
		var hash = location.hash;
		if ( hash !== currHash ){
			/// set url hash to current hash
			currHash = hash;
			/// load content
			var lc = loadContent(hash);
		}
	}
		
	setInterval("checkHash()", 300);	
	
	
$(function(){
	
	// ====================================================================================
	// Prevent ajax calls from being cached
	// ====================================================================================
	
	$.ajaxSetup({
	    cache: false
	});

	/// if IE
	if($.browser.msie){	
		$("body").prepend("<iframe id='inframe_processor_iframe'></iframe>");
	}
	$("body").prepend("<img id='loading' src='/images/ajax-loader.gif'/>");
	
	var siteURL = "http://" + top.location.host.toString();
	var $internalLinks = $("a[href^='"+siteURL+"'], a[href^='/'], a[href^='./'], a[href^='../'], a[href^='#']").not(".no_ajax");
	
	$internalLinks.livequery("click", function(){

		$("body").addClass("waiting");
		/// if IE
		 if($.browser.msie){	
			/// send info to inframe_processor to switch hash (works with IE)
			$("#inframe_processor_iframe").attr("src", "/system/inframe_processor.php?p="+$(this).attr("href"));
		} else {
			location.hash = $(this).attr("href");			
		}
		return false;
	});
});	
