$(document).ready(function(){
	// Afficher l'année courante dans le <span class="annee">
	function setSelected(el) { $(el).replaceWith('<li class="selected">'+$(el).text()+'</li>'); } //(tout sur une ligne pour éviter un plantage de IE6)
  $('span.annee').text((new Date()).getFullYear());
  // Modifier le menu principal pour afficher l'élément sélectionné (tout sur une ligne pour éviter un plantage de IE6)
	$('ul.menu').each(function(i,ul) { var lis = $(ul).children('li'); bestMatch = { 'index': 0, 'length': -1 }; for(j=0; j<lis.length; j++) { var url = $(lis[j]).children('a').attr('href'); if (window.location.pathname.match("^" + url)) { if(url.length > bestMatch.length) { bestMatch.index = j; bestMatch.length = url.length; } } } if(bestMatch.index >= 0 ) { setSelected(lis[bestMatch.index]); } });
  /*$('ul.menu').each(function(i,ul) {
    var lis = $(ul).children('li');
		bestMatch = { 'index': -1, 'length': -1 };
		if(console) { console.log('--- STARTING NEW MENU ---'); }
		for(j=0; j<lis.length; j++) {
			var url = $(lis[j]).children('a').attr('href');
			if(console) { console.log(window.location.pathname + ' <--> ' + url); }
			if (window.location.pathname.match("^" + url)) {
				if(console) { console.log('match'); }
				if(url.length > bestMatch.length) {
					if(console) { console.log('best match so far'); }
					bestMatch.index = j;
					bestMatch.length = url.length;
				}
			}
		}
		if(bestMatch.index >= 0 && !(bestMatch.index == 0 && !window.location.pathname.match(/\/(index.php)?$/))) {
			setSelected(lis[bestMatch.index]);
		}
	});*/
	// Transformer les <span class="more"> en textes escamotables
  $('<a href="javascript:;" class="more">'+traductions['plus']+'</a>').insertAfter($("span.more").hide());
  $('a.more').toggle(function() {
		$(this).text(traductions['moins']).prev().show();
  }, function() {
		$(this).text(traductions['plus']).prev().hide();
  });
	// Transformer les systèmes div more en textes escamotables
	$("div.less").show();
	$("div.more").hide();
	$("span.showmore").append('<a href="javascript:;" class="divmore">'+traductions['plus']+'</a>');
	$("span.showless").append('<a href="javascript:;" class="divless">'+traductions['moins']+'</a>');
	$('a.divmore').click(function() {
    $(this).closest('div.less').hide().next('div.more').show();
  });
	$('a.divless').click(function() {
    $(this).closest('div.more').hide().prev('div.less').show();
  });
});

// Fil d'ariane (breadcrumbs)
function createBreadcrumbs(ulMenu, container) {
	function up(lnk,ulMenu) {
		var node = $(lnk).parent().parent().parent();
		return $(node).is('li') && $(ulMenu).has(node) ? $(node).find('a').first() : false;
	}
	function pathname(lnk) { return lnk.pathname.match(/^\//) ? lnk.pathname : '/' + lnk.pathname; /* IE ne retourne pas de slash au début du pathname */ }
	var lnk = $(ulMenu).find('a[href='+window.location.pathname+']');
	$(container).prepend(lnk.clone().wrapInner('<strong />'));
	while(lnk = up(lnk, ulMenu)) {
		$(container).prepend(" » ");
		$(container).prepend(pathname(lnk[0]) == window.location.pathname ? lnk.text() : lnk.clone());
	} 
}
