$(function() {
	
	$(".xClose").hide();
	
	$("li.notOn .aMenu").click(function() {
		
		
		//alert( $(this).parents("li").children("ul").attr('class') );
		if( $(this).parents("li").children("ul").attr('class') == "sMenu xSelected")
		{
			
			// s'il est ouvert
			//alert("on ferme");
			//alert($(this).attr('class'));
			
			$(".xSelected").removeClass("xSelected");
			$(this).parents("li").children("ul").addClass("xClose");
			$(this).parents("li").children("ul").slideUp("slow");
			$(this).parents("li").removeClass("son");
			$("li.notOn .xOpen").slideUp("slow");
		}
		else
		{
			// s'il est fermé :
			//alert("on ouvre");
			$(".xSelected").slideUp("slow");
			$(".xSelected").parents("li").children("a").stop().animate({ backgroundColor:"black" } , 1000 );
			$(".xSelected").removeClass("xSelected");
			
			$(this).parents("li").children("ul").addClass("xSelected");
			
			$(this).parents("li").children("ul").removeClass("xClose");
			
			$(".son").removeClass("son");
			$(this).removeClass("mHover");

			$(this).parents("li").children("ul").slideDown("slow");
			$(this).parents("li").addClass("son");
			
		}
		
		/*
		$(this).addClass("mOpen");
		$(this).removeClass("aMenu");
		*/
		
		/*
		$(".xOpen").addClass("xClose");
		$(".xOpen").removeClass("xOpen");
		$(this).parents("li").children("ul").show();
		$(this).parents("li").addClass("son");
		$(this).parents("li").children("ul").addClass("xOpen");
		*/
		return true;
	});
	
	
	$("li.notOn a.mHover").hover(function() {
		//alert($(this).parents("li").children("ul").attr('class'));
		if($(this).parents("li").children("ul").attr('class') != "sMenu xSelected")
		{ $(this).stop().animate({ backgroundColor:"white" } , 1 ); }
	}, function(){
		if($(this).parents("li").children("ul").attr('class') != "sMenu xSelected")
		{ $(this).stop().animate({ backgroundColor:"black" } , 1000 ); }
	});
	
});

