$(function(){
	//On cache le loader de base
	$('#loader').hide();
	$('#temp').hide();
	$('a:not(.notajax)').live('click',function(){
		var $this = $(this);
			$("#main").css({ opacity: 0.3 });
			//on montre le loader
			$('#loader').show();
			//on charge la page
			loadPage ($this.attr('href'), function(){
			//on remasque le loader
			$('#loader').hide();
			$("#main").css({ opacity: 1 });
			});
		return false ;
	});
	
	if(ancre = window.location.hash) loadPageAncre(ancre.substr(2));
	
	/* ******************   FANCYBOX   ****************** */
	
	$('a.fancy').live('click',function(){
		var $this=$(this);
		var $src = $this.attr('href');
		var $title = $this.attr('title');
		$.fancybox({
			'href':$src,
			'title':$title,
			'overlayShow'	: true,
			'transitionIn'	: 'elastic',
			'transitionOut'	: 'elastic'
		});
		return false;
	});
	
});


function loadPage(href, callback){
	$.get(href, function(response){
		$('#main').html($(response).find('#main').html());
		/*$('#temp').html(response);
		$('title').html($('#temp title'));
		alert($('#temp').html());*/
		//var urllength = ((window.location.href).length) - ((window.location.hash).length);
		urllength = 20;
		window.location.hash = href.substr(urllength);
		if(callback!=undefined) callback(response);
	});	
}

function loadPageAncre(href, callback){
	$.get(href, function(response){
		$('#main').html($(response).find('#main').html());
		window.location.hash = href.substr() ;
		if(callback!=undefined) callback(response);
	});	
}
