//On load page, init the timer which check if the there are anchor changes each 300 ms
$().ready(function(){
	setInterval("checkAnchor()", 200);
	//$("#colorMenu").livequery(); $("#colorPage").livequery();
});
//var currentAnchor = '#photographe';
var currentAnchor = null;
//Function which chek if there are anchor changes, if there are, sends the ajax petition
function checkAnchor(){
	//alert(currentAnchor);
	//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=photographe";
		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 randomnumber = Math.floor(Math.random()*111);
		
		// if folio -> arrow
		if (currentAnchor && (currentAnchor!= '#resume') && (currentAnchor!= '#contact') && (currentAnchor!= '#photographe')){
			var arrowTop = $('a[href='+currentAnchor+']').position().top;
			if (arrowTop<5) arrowTop = 24;
			$("#arrow").animate({'top': arrowTop+'px'},"fast");
			$("#arrow").css({'display':'block'});
		}else{
			$("#arrow").css({'display':'none'});
		}
		
		// if bold...
		if ( (currentAnchor== '#resume') || (currentAnchor== '#contact') ){
			$("#menu a").css({'font-weight':'normal' });
			$('a[href='+currentAnchor+']').css({'font-weight':'bold' });
		}else{
			if (currentAnchor && (currentAnchor!= '#photographe')) {
				//alert('bob');
				$("#menu a").css({'font-weight':'normal' });
				$("#menu a:first").css({'font-weight':'bold' });
			}
		}
		if (currentAnchor=='#photographe') {
			$("#menu a").css({'font-weight':'normal' });
		}

		// chargement
		$("#loading").css({'display':'block' });
		//var rand = Math.round(Math.random() * 6);
		$.get("/inc/ajaxContent.inc.php?",query, function(data){
			$("#bRight").fadeOut("fast", function() { 
				$("#bRight").html(data); 
				var pageCol = $("#colorPage").val();
				$("#bRight").css({'background-color':'#'+pageCol }); 
			});
			$("#bRight").fadeIn("400", function() { 
				$("#loading").css({'display':'none' });
			});
			//load("#bRight");
			setTimeout(function() {
				var menuCol = $("#colorMenu").val();
				$("#bLeft").css({'background-color':'#'+menuCol});
				}, 300); 
			
			//alert(menuCol);
			
		});
	}
}

