$(document).ready(function(){	//executed after the page has loaded
	checkURL();	//check if the URL has a reference to a page and load it
	$('#menu li a,#categories li a').click(function (e){	//traverse through all our navigation links..
			checkURL(this.hash);	//.. and assign them a new onclick event, using their own hash as a parameter (#page1 for example)
	});
	setInterval("checkURL()",250);	//check for a change in the URL every 250 ms to detect if the history buttons have been used
});

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 name

	//$('#loading').css('visibility','visible');	//show the rotating gif animation

	$.ajax({	//create an ajax request to load_page.php
		type: "POST",
		url: "load_file.php",
		data: 'page='+url,	//with the page number as a parameter
		dataType: "html",	//expect html to be returned
		success: function(msg){

			if(parseInt(msg)!=0)	//if no errors
			{
				$('#corps').html(msg);	//load the returned html into pageContet
				//$('#loading').css('visibility','hidden');	//and hide the rotating gif
				$('.claudeslide').nivoSlider({
					effect:'boxRandom,boxRain,boxRainReverse',
					animSpeed: 500,
					pauseTime: 3000,
					directionNav: false, // Next & Prev navigation
					directionNavHide: true, // Only show on hover
					controlNav: false, // 1,2,3... navigation
					pauseOnHover: false
				});
			}
		}
	});
	if(url == "apropos")
	{
		$("#menu1").attr("class", "menu1select");
		$("#menu2").attr("class", "menu2");
		$("#menu3").attr("class", "menu3");
	}
	else if(url == "contact")
	{
		$("#menu1").attr("class", "menu1");
		$("#menu2").attr("class", "menu2");
		$("#menu3").attr("class", "menu3select");
	}
	else {
		$("#menu1").attr("class", "menu1");
		$("#menu2").attr("class", "menu2select");
		$("#menu3").attr("class", "menu3");
	}
}
