var href;
var done;
var loaded;
var id;

$(document).ready(function(){
	$('#header').click(function(){
		window.location.href="/";
	});
	$("#navigation a, .funkylink").click(function(event){
		// Only do this in non mobile view
		if($('.mobileshow').css('display')=='none'){
			// Prevent normal click
			event.preventDefault();

			// Initialise
			href=$(this).attr('href').replace('/','');
			id=href.replace('.','_');
			done=0;
			loaded=0;
			
			// Remove map if exists (causes errors)
			$('#map_canvas').css('display','none');
			
			// Animate slide
			$('#pagecontent').animate({paddingLeft: $('#pagecontent').innerWidth()+100, width: $('#pagecontent').width()},750,'swing',function(){
				if(loaded==1){
					showPage('#' + id);
				}
				done=1;
				});

			$('#pagecontent').after('<div style="display: none;" id="' + id + '">Loading...</div>');
			$('#' + id).load($(this).attr('href') + ' #pagecontent', function(){
				$(this).html($(this).find('#pagecontent').html());
				if(done==1){
					showPage('#' + id);
				}
				loaded=1;
			
			});
		}
   	});
});
 
function showPage(id){
	$('#pagecontent').html($(id).html());
	$('#pagecontent').animate({paddingLeft: '0.5em'},750,'swing',function(){
		$('#pagecontent').css({width: 'auto'});
		window.location.href='/' + href;
	});
}

