$().ready(function(){
	setInterval("checkAnchor()", 300);
});

//References
var loading = $("#loading");
var content = $("#content");
var pageNum;
var currentAnchor = null;

//show loading bar
function showLoading(){
	loading.slideDown("slow");
}
//hide loading bar
function hideLoading(){
	loading.slideUp("slow");
};

function checkAnchor(){
	//Check if it has changes
	if(currentAnchor != document.location.hash){
		currentAnchor = document.location.hash;
		//if there is not anchor, the loads the default section
		if(!currentAnchor)
		{
			//default - page = 1
			pageNum = 1;
		}
		else
		{
			//get the page number after #
			pageNum = currentAnchor.substring(1);
		}
		//Send the petition and display the result
		showLoading();
		var targetUrl = "content.php?page=" + pageNum + "&" + $("#myForm").serialize() + " #content";
		content.load(targetUrl, hideLoading);
		
		//reset all link and highlight the current page link
		$("#pages a").css({'background-color':''})
		$("#pages a[href='#"+ pageNum +"']").css({'background-color':'yellow'});
	}
}