$(function(){
	//Cache les images au chargement de la page
	var imgHidden = $("div.hidden");
	imgHidden.hide();
	
	//ajoute le lien 'ouvrir'
	$("p.link").prepend('<a class="open" alt="Ouvrir">Ouvrir</a>&nbsp;|&nbsp;');
	
	//ouerture et fermeture des images
	$(".open").css("cursor", "pointer").click(function(){
		
		if($(this).text() == "Ouvrir"){
			$(this).empty().append("Fermer");
		}else{
			$(this).empty().append("Ouvrir");			
			$(this).attr('href', '#top');
			$(this).parent().prev().children("a").attr('href', '#top');
			$(this).parent().prevAll("a").attr('href', '#top');
		}
		$(this).parent().prev("div.hidden").slideToggle("slow");
	});
	$(".show").css("cursor", "pointer").click(function(){
		
		if($(this).parent().find("a.open").text() == "Ouvrir"){
			$(this).parent().find("a.open").empty().append("Fermer");
		}else{
			$(this).parent().find("a.open").empty().append("Ouvrir");
			$(this).attr('href', '#top');
			$(this).nextAll().children("a.open").attr('href', '#top');
			$(this).next("div.hidden").children("a").attr('href', '#top');
		}
		$(this).next("div.hidden").slideToggle("slow");
	});
	imgHidden.css("cursor", "pointer").click(function(){			
		if($(this).parent().find("a.open").text() == "Ouvrir"){
			$(this).parent().find("a.open").empty().append("Fermer");
		}else{
			$(this).parent().find("a.open").empty().append("Ouvrir");
			$(this).children("a").attr('href', '#top');
			$(this).prevAll("a").attr('href', '#top');
			$(this).next().children("a.open").attr('href', '#top');
		}
			
		$(this).slideToggle("slow");
	});
});
