// JavaScript Document 
    function troca_fundo() {

    // quantas fotos
    var quantas = 5;

    // pegando o número aleatório
    var numero_random = Math.floor(Math.random()*11);

    // aplicando o background na div
    $("html").css("background-image","url(images/bkg/back_0"+numero_random+".jpg)");

    };

//On load page, init the timer which check if the there are anchor changes each 300 ms
//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowHeight = document.documentElement.clientHeight;
	var windowWidth = document.documentElement.clientWidth;
	var popupHeight = $("#loading img").height();
	var popupWidth = $("#loading img").width();
	//centering
	$("#loading").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}




$().ready(function(){

		troca_fundo();
	

	setInterval("checkAnchor()", 300);
});
	//show loading bar
		function showLoading(){
			centerPopup();
			$("#loading").fadeIn('slow');
			popupStatus = 0;
			loadPopup();	
			}
	  //hide loading bar
	  function hideLoading(){
		  
		  $("#loading").fadeOut('slow');
		  popupStatus = 1;
		  disablePopup();
			 }
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;
		//if there is not anchor, the loads the default section
		if(!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 section = splits[0];
			delete splits[0];
			//Create the params string
			
			var params = splits.join('&');
			var query = 'section=' + section + params;
			
		}
		if(!currentAnchor){
			
			
			
		}
		else
		{	
		//Send the petition
			showLoading();
			troca_fundo();
 			$.post("callbacks.php",query, function(data){
			$("#main_content").html(data);
			hideLoading();
		
		 }); 
		} 
	}
}


