var tm_menu1, tm_menu2, speed;
speed = 200;

$(document).ready(function(){
    
	// -- Menu ------->
	
	$("ul#menu > li > a").hover(function(){
		$(this).stop().animate({paddingTop:"20px", paddingBottom:"20px"}, 200);
	},function(){
		$(this).stop().animate({paddingTop:"28px", paddingBottom:"0"}, 300);
	});
	
	
	// -- Liens externes ------->
	
	liensExternes();
	
	
	// -- Gestion des sous-menu ------->
	
	$(".smenu").next().css({
		opacity: 0,
		visibility: 'hidden'
	});
	
	$("#smenu1_btn").hover(
		function(){
			afficher_menu(1);
		},
		function(){
			tm_menu1 = setTimeout("cacher_menu(1)", speed);
		}
	);
	
	$("#smenu1 li a").hover(
		function(){
			afficher_menu(1);
		},
		function(){
			tm_menu1 = setTimeout("cacher_menu(1)", speed);
		}
	)
	
	$("#smenu2_btn").hover(
		function(){
			afficher_menu(2);
		},
		function(){
			tm_menu2 = setTimeout("cacher_menu(2)", speed);
		}
	);
	
	$("#smenu2 li a").hover(
		function(){
			afficher_menu(2);
		},
		function(){
			tm_menu2 = setTimeout("cacher_menu(2)", speed);
		}
	)
	
	$("ul#menu li ul li a").hover(function(){
		$(this).stop().animate({paddingLeft:"15px"}, 200);
	},function(){
		$(this).stop().animate({paddingLeft:"11px"}, 200);
	});
	
});

function afficher_menu(no){
	if(no==1){
		clearTimeout(tm_menu1);
		$("#smenu1").css("visibility","visible");
		$("#smenu1").stop().animate({
			opacity: 1
		}, speed);
	}else{
		clearTimeout(tm_menu2);
		$("#smenu2").css("visibility","visible");
		$("#smenu2").stop().animate({
			opacity: 1
		}, speed);
	}
}

function cacher_menu(no){
	$("#smenu"+no).stop().animate({
		opacity: 0
	}, speed);
	if(no==1){
		tm_menu1 = setTimeout("menu_invisible(1)", speed)
	}else{
		tm_menu2 = setTimeout("menu_invisible(2)", speed)
	}
}

function menu_invisible(no){
	$("#smenu"+no).css("visibility","hidden");
}

function liensExternes(){
	$("a.lienExt, a.lienExt-inv").click(function(event){
		window.open( $(this).attr('href') );
        return false;
	});
}
