// En Savoirplus
$(document).ready(function(){
	
	$(".ensavoirplus_titre").each(function(idx, el){
		var tmp = "<div class='ensavoirplus'><h3 class='ensavoirplus_titre'>"+ $(this).html() + "</h3>";
		var v = $(this).next();
		var fin = false;
		while(v.hasClass("ensavoirplus_contenu") && !fin)
		{
			tmp +=  ("<p class='ensavoirplus_contenu'>" + v.html() + "</p>");
			v = v.next();
			if(v.html() == null) //pas de next(on detruit le courant)
			{
				fin=true;
			}
			else
				v.prev().remove();
		}
		tmp +=  "</div>";
		$(this).replaceWith(tmp);
		if(fin)
		{
			$(".ensavoirplus_contenu:last").remove();
		}
	});
//	$(".ensavoirplus_contenu").hide();
	$(".ensavoirplus_titre").append("&nbsp;<span class='ensavoirplus_ouvrir'>[+]</span>");

	$(".ensavoirplus_ouvrir").live("click",function(){
		$(this).parent().parent().children(".ensavoirplus_contenu").slideDown("fast");
		$(this).replaceWith("<span class='ensavoirplus_fermer'>[-]</span>");
		
	});
	$(".ensavoirplus_fermer").live("click",function(){
//		alert($(this).parent().parent().html());
		$(this).parent().parent().children(".ensavoirplus_contenu").slideUp('fast');
		$(this).replaceWith("<span class='ensavoirplus_ouvrir'>[+]</span>");
	});
	
//	$("div.showr").click(function () { 
//		var premierparent = $(this).parents("div.letitre") ;
//	  $(premierparent).children("div.showr").hide(0);
//	  $(premierparent).children("div.hidr").show(0) ;
//		var divparent = $(this).parents("div.btouvrable") ;
//	  $(divparent).children("div.contents").show(0) ;
//	});
//	$("div.hidr").click(function () { 
//		var divparent = $(this).parents("div.btouvrable") ;
//	  $(divparent).children("div.contents").hide(0) ;
//	  var premierparent = $(this).parents("div.letitre") ;
//	  $(premierparent).children("div.showr").show(0);
//	  $(premierparent).children("div.hidr").hide(0) ;
//	});
})

