//On load page, init the timer which check if the there are anchor changes each 300 ms
$().ready(function(){
	setInterval("checkAnchor()", 300);
});
var tytulStrony = $("title").text();
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
	//alert(currentAnchor);
	if(currentAnchor != document.location.hash.replace("!","")){
		currentAnchor = document.location.hash.replace("!","");
		//if there is not anchor, the loads the default section
		if(!currentAnchor || currentAnchor=="#")
		{
			
		}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 podstrona = splits[0];
			delete splits[0];
			//Create the params string
			var params = splits.join('&');
			var query = "podstrona=" + podstrona + params;
			//alert(podstrona);

    		var link = "#!"+podstrona;
            
    		$("#menug a").css({backgroundColor: "#FFFFFF", color: "#5f9110"});
    		$('#menug a[href="'+link+'"]').css({backgroundColor: "#bedd00", color: "#FFFFFF"});
   			
            var widok = $("#podstrona").css("display");
    		if(widok=="none")
    		{
    		  $('.overlay').css({display: "block", opacity: "0"}).animate({opacity: "0.2"});
    		  $("#podstrona").css({display: "block"});//.animate({opacity: "1"});
    		}
    	
            if(podstrona!="galeria" && podstrona!="aktualnosci")
            {
                $.get("callbacks.php",query, function(data){
        			$("#podstrona").html(data);
                    $("title").text(tytulStrony+" :: "+$(".top").text());
        		});
        	}
        	if(podstrona=="galeria")
        	{
                $.get("galeria.php",query, function(data){
        			$("#podstrona").html(data);
                    $("title").text(tytulStrony+" :: Galeria");
        		});
        	}
        	if(podstrona=="aktualnosci")
        	{
            $.get("aktualnosci.php",query, function(data){
        			$("#podstrona").html(data);
                    $("title").text(tytulStrony+" :: Aktualności");
        		});
        	}
    


		}
	}
}
