var default_content="";
var current_portfolio_item=0;

$(document).ready(function(){
	
	//	Load the initial page
	loadPage('#home');
	
	checkURL();
	$('a').click(function (e){

			checkURL(this.hash);
			
	});
	
	//filling in the default content
	default_content = $('#content').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=="")
		$('#content').html(default_content);
		
		else
		loadPage(hash);
	}
}


function loadPage(url)
{

	url=url.replace('#','');
	
	$('#loading').css('visibility','visible');
	$('body').css('cursor','wait');
	
	$.ajax({
		type: "GET",
		url: "ajax/pagefetch.php",
		data: 'page='+url,
		dataType: "html",
		success: function(msg){
			
			if(parseInt(msg)!=0)
			{
				$('#content').html(msg);
				$('#loading').css('visibility','hidden');
				$('body').css('cursor','auto');
			}
		}
		
	});

}

function showPortfolioItem(id)
{

	if(id != current_portfolio_item)
	{
		$('#portfolioitemcontainer'+current_portfolio_item).css('display','none');
		$('#portfolioitemcontainer'+id).css('display','inline');
		current_portfolio_item = id;
	}
}
