//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 chek 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;
		
		var query = null;
		
		//if there is not anchor, the loads the default section
		if(!currentAnchor)
			//query = "section=home";
			query = "about"
		else
		{
			//Creates the  string callback. This converts the url URL/#main&id=2 in URL/?section=main&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;
			var query = section;
		}
		//Send the petition
//		$.get("callbacks.php",query, function(data){
//			$("#content").html(data);
//		});
		ajaxRequest(query,"content");

	}
}







function ajaxRequest(cmd,dest) {
/*
var xmlHttp;
var ajaxReturn;

try { xmlHttp=new XMLHttpRequest(); }
catch (e) {
	try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e) {
			try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }
			catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
*/

	// /* Create a new XMLHttpRequest object to talk to the Web server */
	var xmlHttp = false;
	// /*@cc_on @*/
	// /*@if (@_jscript_version >= 5)*/
	try 
	{ 
		xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	} 
	catch (e) 
	{
	  try 
	  {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	  } 
	  catch (e2) 
	  {
		xmlHttp = false;
	  }
	}
	// /*@end @*/
	
	if (!xmlHttp && typeof XMLHttpRequest != 'undefined') 
	{
	  xmlHttp = new XMLHttpRequest();
	}

	if (!xmlHttp)
     alert("Error initializing XMLHttpRequest!");


 	// Build the URL to connect to
  	var url = "contentHandler.php?q="+cmd;


	xmlHttp.onreadystatechange=function() 
	{
		if(xmlHttp.readyState==4) 
		{ 
			if (xmlHttp.status == 200)
			{
				window.document.getElementById(dest).innerHTML='';
				window.document.getElementById(dest).innerHTML=xmlHttp.responseText.replace('<img src="../../img_web/', '<img src="../img_web/'); 
				if(cmd!="about")
				{
					try {
					var pageTracker = _gat._getTracker("UA-4443243-2");
					pageTracker._trackPageview(cmd);
					} catch(err) {}						
				}
				
				var linksArray = window.document.getElementsByTagName('a');
				
				for (i = 0; i < linksArray.length; i++)
				{
					if(linksArray.item(i).id == "js")
					{
						linksArray.item(i).style.visibility = 'visible';
					}
					else if(linksArray.item(i).id == "non_js")
					{
						linksArray.item(i).style.visibility = 'hidden';
					}
					
				}


			}
			else
			{
				alert("Error: status code is " + request.status);
			}
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);

}