$(document).ready(function()
{
	$(".lamp").lavaLamp(
	{
		fx: 'easeOutExpo',
		speed: 400,
		autoReturn: false
	});
	
	$(".lamp").mousemove(function(e) 
	{
		if($(this).height() > $(".cache").height()) 
		{
			var distance = e.pageY - $(this).offset().top;
			var percentage = (distance-30) / ($(this).height()-60);
			var targetY = Math.round(($(".cache").height() - $(this).height()) * percentage);
			$('.lamp').animate({top: [targetY+"px", "easeOutCirc"]}, { queue:false, duration:200 });
		}
	});

	var timeout;
			
	$("#ssMenu li.BtnCorps").each
	(
		function()
		{
			$(this).mousemove
			(
				function () 
				{
					clearTimeout(timeout);
					timeout = setTimeout("afficheSsMenu('" + $(this).attr('id') + "');",100);	
				}
			);
			
			$(this).hover
			(
				function () {},
				function () 
				{
					clearTimeout(timeout);	
				}
			);
		}
	);	
	
	
	$('#ssMenu').hover
	(
		function() {},
		function() {cacherSsMenu()}
	);
	
	$("#headerBottom .ssMenuDefault .colonneGrise ul li.li_famille").mouseover
	( 
		function() 
		{
			clearClassHover();
			
			tab = $(this).attr('id').split('_');
			id_rayon = tab[1];
			id_famille = tab[2];
			
			id_parent = $(this).parent().parent().parent().parent().attr('id');
			
			$("#headerBottom #" + id_parent + " .liens .div_ssfamille_" + id_rayon).hide();			
			$("#headerBottom #" + id_parent + " .liens div.famille_" + id_rayon + "_" + id_famille).show();
		}
	);
	
	$("#headerBottom .ssMenuDefault .liens .contenu_liens").mouseover
	( 
		function() 
		{
			tab = $(this).attr('class').split(' ');
			
			for(i=0; i<tab.length; i++)
			{
				if(tab[i].indexOf('famille_') != -1)
				{
					tab2 = tab[i].split('_');
					id_rayon = tab2[1];
					id_famille = tab2[2];
				}
			}
			
			clearClassHover();
			addClassHover(id_rayon,id_famille);
		}
	);
});

function afficheSsMenu(id)
{
	$('#carrousel').hide();
	$('.ssMenuDefault').hide();
	$('#' + id + '_SsMenu').show();
	clearClassHover();
	$('#' + id + '_SsMenu .colonneGrise ul li:first').addClass("famille_hover");
	$('.lamp li').css('top',0);
	$('.lamp').css('top',0);
	$('#' + id + '_SsMenu .contenu_liens').hide();
	$('#' + id + '_SsMenu .contenu_liens:first').show();
}

function cacherSsMenu()
{
	$('.ssMenuDefault').hide();
	$('#carrousel').show();
	clearClassHover();
}				

function addClassHover(id_rayon,id_famille)
{
	$(".li_" + id_rayon + "_" + id_famille).addClass("famille_hover");
}				

function clearClassHover()
{
	$("#headerBottom .ssMenuDefault .colonneGrise ul li.li_famille").removeClass("famille_hover");
}				


