﻿$(document).ready(function() {  
     
	$('#contact_form label.error').hide();  
	$('#menubar ul').removeClass('no-js');	
	
	var trial = "#menubar ul.lavaLamp li a, #sidebar ul li a";
	swapAnchors(trial); 
	checkURL();	//check if the URL has a reference to a page and load it

	$('#menubar ul.lavaLamp li a, #sidebar ul li a').livequery('click', function (e){	//traverse through all our navigation links..
			$('#content_holder').slideUp('slow');
			checkURL(this.hash);	//.. and assign them a new onclick event, using their own hash as a parameter (#page1 for example)
			swapAnchors('#sidebar ul li a');
			$('#content_holder').slideDown('slow');
	});

	setInterval("checkURL()",250);	//check for a change in the URL every 250 ms to detect if the history buttons have been used

});

function swapAnchors(x) 
{
	$(x).attr('href', function() {
		newAnchor = $(this).attr('href').replace('.php','');
		return '#'+newAnchor;
	});
}

var lasturl="";	//here we store the current URL hash

function checkURL(hash)
{
	if(!hash) hash=window.location.hash;	//if no parameter is provided, use the hash value from the current address

	if(hash != lasturl)	// if the hash value has changed
	{
		lasturl=hash;	//update the current hash
		loadPage(hash);	// and load the new page
	}
}

function loadPage(url)	//the function that loads pages via AJAX
{
	url=url.replace('#','');	//strip the #page part of the hash and leave only the page number
	url=url+'.php';
	$('#loading').css('visibility','visible');	//show the rotating gif animation
	var toLoad = url+' #content';  
	$('#content').load(toLoad);
}