/* passe en ajax tous les liens rel="remote" sans ancre */
function remoteAll() {

  //  .remote('#contenu', {defaultHash: 'accueil'}, remoteAll);
  
}

// PageLoad function
// This function is called when:
// 1. after calling $.historyInit();
// 2. after calling $.historyLoad();
// 3. after pushing "Go Back" button of a browser
function pageload(hash) {
	if(hash) {	// hash doesn't contain the first # character.
		// restore ajax loaded state
		var tailleProtocole = 8; 
		var domaine = window.location.href;
		domaine = domaine.substring(0, domaine.indexOf('/',tailleProtocole));

		// on remet le domaine au hash
		$("#contenu").load(domaine +'/'+ hash, {}, contenuCharge);
	} 
}

/* Méthode relancée à chaque chargement contenu ajax */
function contenuCharge() {
	Cufon.replace('#contenu h1');
	$('a[rel=externe]').attr('target', '_blank');
}

$(function(){
	
	/* Hijax */
	$('a[rel=remote]:not([href*=#])').live('click', function(){
		var hash = this.href;
		hash = hash.replace(/^.*#/, ''); // vire l'ancre
		hash = hash.replace(/http:\/\/[^\/]+\//, ''); // vire le domaine
		
		// moves to a new page. 
		// pageload is called at once. 
		// hash don't contain "#", "?"
		$.historyLoad(hash);
		return false;
	});
	// Initialize history plugin.
	// The callback is called at once by present location.hash. 
	$.historyInit(pageload);

	Cufon.replace('.middle_box h1 a');
	contenuCharge();

	/* Lecteur audio */
	lecteur.init();
});

