// Gestion des binds
function getArbreNumber(obj) {
	objClass = obj.attr("class");
	posArbre = objClass.indexOf("arbre");
	if(posArbre!=-1) return objClass.substring(posArbre+5, posArbre+6);
	else return "";
}

function brancheActive(obj, pos, type) {
	var text = null, feuille = null;
	if(obj.attr("id").substring(0,5)=="texte") {
		text = obj; feuille=$("#arbre-images div.arbre"+pos).children();
	} else {
		feuille = obj.children(); text=$("#arbre-complet a.arbre"+pos);
	}
	text.addClass(type);
	text.addClass(type+pos);
	feuille.addClass(type);
}


function brancheDesctive(obj, pos, type) {
	var text = null, feuille = null;
	if(obj.attr("id").substring(0,5)=="texte") {
		text = obj; feuille=$("#arbre-images div.arbre"+pos).children();
	} else {
		feuille = obj.children(); text=$("#arbre-complet a.arbre"+pos);
	}
	text.removeClass(type);
	text.removeClass(type+pos);
	feuille.removeClass(type);
}

function initArbre() {
	$("#arbre-complet a.arbtexte, #arbre-images div.prefeuille").each(function() {
		arbreNum = getArbreNumber($(this));
		$(this).bind('mouseenter', {arbreNum:arbreNum}, function(event) { brancheActive($(this), event.data.arbreNum, "hover"); });
		$(this).bind('mouseleave', {arbreNum:arbreNum }, function(event) { brancheDesctive($(this), event.data.arbreNum, "hover"); });
		$(this).bind('click', {arbreNum:arbreNum }, function(event) { 
			var thisActif = $("#arbre-complet a.actif")
			if(thisActif!= null) brancheDesctive(thisActif, getArbreNumber(thisActif), "actif");
			brancheActive($(this), event.data.arbreNum, "actif");

			//Affichage des §
			var pos;
			if(thisActif!= null) {
				pos = thisActif.attr("id").indexOf("_");
				$("#valeur-mutualiste-"+thisActif.attr("id").substring(pos+1)).hide("slow");
			}
			pos = $(this).attr("id").indexOf("_");
			$("#valeur-mutualiste-"+$(this).attr("id").substring(pos+1)).show("slow");
			pageTracker._trackPageview(location.pathname+'?valeur'+pos);
			return false;
		});
	});
}
