var default_content="";

$(document).ready(function(){
	try{
		$('#loading').css('visibility','hidden');
	}catch(e){}
	
	checkURL();
	$('ul li a').click(function (e){

			checkURL(this.hash);

	});
	
	//filling in the default content
	default_content = $('#pageContent').html();
	
	setInterval("checkURL()",250);
	
});

var lasturl="";

function checkURL(hash)
{

	if(!hash) hash=window.location.hash;

	if(hash != lasturl)
	{

		lasturl=hash;

		// FIX - if we've used the history buttons to return to the homepage,
		// fill the pageContent with the default_content

		if(hash=="")
		$('#pageContent').html(default_content);

		else
		loadPage(hash);

	}

}

function loadPage(url)
{
	try{
		$('#pageContent').html('');
		$('#loading').css('visibility','visible');
	}catch(e){}
	url=url.replace('#page','');
	url=url.replace('#','');

	$.ajax({
		type: "POST",
		url: url,
		dataType: "html",
		success: function(msg){

			if(parseInt(msg)!=0)
			{
				$('#pageContent').html(msg);
				try{
					$('#loading').css('visibility','hidden');
				}catch(e){}
			}

		}

	});

}

