$(document).ready(function() {
	
	var image;
	var imgsrc;
	var rollsrc;
	var rollOn;
	
	// Gestion des rollovers du menu de navigation
	var navItems = $("#navigation > ul > li");
	
	navItems.mouseover(function(){
		image = $(this).children(".title").children("img");
		imgsrc = image.attr("src");
		
		var matches = imgsrc.match(/-on/);
		
		if (!matches) {
			imgsrcOn = imgsrc.replace(/.png$/ig,"-on.png");
			image.attr("src", imgsrcOn);
		}
	});
	
	navItems.mouseout(function(){
		image.attr("src", imgsrc);
	});
	
	// Préchargment des images rollover
	$("#navigation img").each(function(){
		rollsrc = $(this).attr("src");
		rollOn = rollsrc.replace(/.png$/ig,"-on.png");
		$("<img>").attr("src", rollOn);
	});
	
	// Gestion des blocs pliables
	$(".foldable").each(function(){
		var block = $(this);
		var title = $(this).children("h5");
		var content = $(this).children("div");

		if(block.hasClass("folded")){
			content.hide();
		}
		
		title.css("cursor","pointer");
		title.click(function(){
			content.slideToggle(200);
			block.toggleClass("folded");
		})
	})
	
	// Gestion des champs textes pré-remplis
	$("input.textinput").each(function(){
		var defaultValue = $(this).val();
		
		$(this).focus(function(){
			if($(this).val() == defaultValue) $(this).val("");
		})
		
		$(this).blur(function(){
			if($(this).val() == "") $(this).val(defaultValue);
		})
	})
	
	// Gestion du bloc d'alerte
	$("div.alert").each(function(){
		var alertBox = $(this);
		var closeLink = $(this).children("div.close").children("a");
		closeLink.click(function(){
			alertBox.slideUp(200);
		})
	})
	
})
