$(document).ready(function(){
	// diaporama
	$.ajax({
		type: "GET",
		url: "diapo.php",
		cache: false,
		success: function(html)
		{
			$("div#contenu-diapo").html(html);
			$("div#contenu-diapo").fadeIn(200);
		}
	});
	$("ul#menuDiapo a").click(function(){
		var idA = $(this).attr("id");
		var dataString = 'dossier='+idA ;
		$("div#contenu-diapo div").fadeOut(200, function(){
			$.ajax({
				type: "GET",
				url: "diapo.php",
				data: dataString,
				cache: false,
				success: function(html)
				{
					$("div#contenu-diapo").html(html);
					$("div#contenu-diapo div").fadeIn(200);
				}
			});
		});
	});
	$('#diapo').cycle({
		fx:    'fade',
		timeout: 2000
	});
		
	// fin diaporama
	
	// initialisation du plugin history au chargement de index.html
	$.historyInit(pageload, "accueil.php");
	
	//load la premiere page par defaut si dans l'url pas de '/#page.html'
	
	//Remplacement des liens en html par des liens en php
	/*
	$('a#ajax').each(function() {
		var link=$(this).attr("href");
     	$(this).attr("href",link.replace("html","php"));
     	//window.location.hash = link+".html";
  	});
	*/
	
	//Clic sur les liens history
	$("a[rel='history']").click(function(){
		var hash = $(this).attr("href");
		hash = hash.replace(/^.*#/, '');
		$.historyLoad(hash);
		return false;
	});


	/*
	$('a#ajax').click(function(){
		var link=$(this).attr("href",link);
		link = '/pages/'+link;
		$("#page").load(link).hide().fadeIn("5000");
        //ajax_page_advanced('#page','<img src="images/loading.gif"/>',link);
        return false;
    });
	*/
});

function pageload(hash) {
	// hash doesn't contain the first # character.
	if(hash) {
		hash = hash.replace("html","php");
		// restore ajax loaded state
		if($.browser.msie) {
			// jquery's $.load() function does't work when hash include special characters like aao.
			hash = encodeURIComponent(hash);
		}
		//$("#page").load("/pages_fr/"+hash).fadeIn("5000");	
		$("#page").load("pages_fr/"+hash).fadeIn("5000", function(){
			
			$('#diapo').cycle({
				fx:    'fade',
				timeout: 2000
			});
		});	
		
	}
}

/*
function ajax_page_advanced(ele,msg,url){
	$(ele).fadeIn("3000", function(){
		$(ele).html("<div class='loading'>"+msg+"</div>").fadeIn("100", function(){
			$(ele).load(url, null, function(){
				$(ele).fadeIn("3000");
			});
		});
	});
}
*/




