﻿//On load page, init the timer which check if the there are anchor changes each 300 ms
$().ready(function(){
	setInterval("checkAnchor()", 300);
});
var currentAnchor = null;
//Function which checks if there are anchor changes, if there are, sends the ajax petition
function checkAnchor(){
	//Check if it has changes
	if(currentAnchor != document.location.hash){
		currentAnchor = document.location.hash;

		//if there is no anchor, do nothing
		if(currentAnchor) {
			//Creates the string callback. This converts the url URL/#home&id=2 in URL/?section=home&id=2
			var splits = currentAnchor.substring(1).split('&');
			//Get the section
			var section = splits[0];
			delete splits[0];
			//Create the params string
			var params = splits.join('&');
			var query = "section=" + section + params;

			// Empty the #main div of HTML
			//$("#main").html('');

			//Send the petition
			$.get("assets/ajax/callbacks.php",query, function(data){
				$("#main").html(data);
				// Apply the IE6 PNG fix to newly loaded content
				$("#main").supersleight();
				// rewride the body id - this changes the nav
				var newId = currentAnchor.substring(2).split('/');
				$("body").attr("id", newId[0]);
			});
		}
	}
}