$().ready(function(){  
    setInterval("checkAnchor()", 300);  
});  
var currentAnchor = null;  
var currentAnchorX = 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;  
        //if there is not anchor, the loads the default section  
        if(!currentAnchor)  
        {
            query = "section=home";  
            d = "home";
        }
        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('&');  
	        var d = currentAnchor.split('|')[1];
	        if (d) {} else { d ="home";}
	        if ( d.indexOf('@') >= 0 ){ d = d.split('@')[0];}
	        if ( d.indexOf('~') >= 0 ){ d = d.split('~')[0];}
	        if ( d.indexOf('!') >= 0 ){ d = d.split('!')[0];}
	        if ( d.indexOf('^') >= 0 ){ d = d.split('^')[0];}
	        if ( d.indexOf('&') >= 0 ){ d = d.split('&')[0];}
            var section = splits[0];  
            delete splits[0];  
            var params = splits.join('&');  
            var query = "section=" + section + params;  
        }  
        //Send the petition  
        
        $.get("/load.php",query, function(data){  
            $("#"+d).html(data);  
        });  
    }  
}  

function loadData(div)
{
	if(currentAnchorX != "#"+div)
	{
		currentAnchorX = "#"+div;
		if(!currentAnchorX)  
	    {
	        query = "section="+div;  
	        d = div;
	    }
	    else  
	    {  
	        var splits = currentAnchorX.substring(1).split('&');  
	        var d = currentAnchorX.split('|')[1];
	        if (d) {} else { d =div;}
	        if ( d.indexOf('@') >= 0 ){ d = d.split('@')[0];}
	        if ( d.indexOf('~') >= 0 ){ d = d.split('~')[0];}
	        if ( d.indexOf('!') >= 0 ){ d = d.split('!')[0];}
	        if ( d.indexOf('^') >= 0 ){ d = d.split('^')[0];}
	        if ( d.indexOf('&') >= 0 ){ d = d.split('&')[0];}
	        var section = splits[0];  
	        delete splits[0];  
	        var params = splits.join('&');  
	        var query = "section=" + section + params;  
	        
	    }  

	    $.get("/load.php",query, function(data){  
	        $("#"+d).html(data);  
	    });  
	}
}
