var current;
var next;
$(document).ready(function() {

	// Page d'accueil cache/affiche la description
	$(".box1 .description").hide();
	$(".box1 .titre").click(function() {

		// Si le sous-menu était déjà ouvert, on le referme :
        if ($("span.description:visible", this.parentNode).length == 0) {
        	var TexteSpan = $("span.description strong", this.parentNode).text();
			$("span.description strong", this.parentNode).replaceWith('<a href="'+$(this).attr("href")+'" class="externe" title="En savoir plus">' + TexteSpan + '<\/a>') ;
			        	$(".box1 .description:visible").hide();
        	$("span.description", this.parentNode).slideDown("slow");

        }
        // Si le sous-menu est caché, on ferme les autres et on l'affiche :
        else {
			
            $("span.description", this.parentNode).slideUp("slow");

        }
		return false;
	});

	// Page rubrique coupe et affiche description
	$(".site p.description").each(function(){
		var description = textCutter($.trim($(this).text()),18);
		$(this).attr("title", $.trim($(this).text()));
		$(this).text(description);
		if ($(this).text().length < $(this).attr("title").length) {
			$(this).prepend('<img class="floatright" src="styles/bullet_arrow_down.png" alt="Plus de description" />');
		}

	});	
	
	$(".site p.description").toggle(function(){
		
		$(this).text($(this).attr("title")); 
		if (textCutter($.trim($(this).text()),18).length < $(this).attr("title").length) {
			$(this).prepend('<img class="floatright" src="styles/bullet_arrow_up.png" alt="Moins de description" />');
		}
		
	},function(){ 
		
		$(this).text( textCutter($.trim($(this).text()),18));
		if ($(this).text().length < $(this).attr("title").length) {
			$(this).prepend('<img class="floatright" src="styles/bullet_arrow_down.png" alt="Plus de description" />');
		} 
	});

	// Permet de dimensionner une image grace au css
	if ($(".description img").attr("height")!= '1') { $(".description img").removeAttr("width").removeAttr("height"); }
	if (($(".image img").attr("height"))!= '1') { $(".image img").removeAttr("width").removeAttr("height");}	
});


function textCutter(myText, txtLength)
{
var newText = "";
var arrayWords = myText.split(" ");
for (var i = 0; i < txtLength; i++)
{
if (arrayWords[i])
{
newText += ' ' + arrayWords[i];
}
}
return newText;
}
