var decalageH2eNiveau=-180;
var decalageH3eNiveau=3;
var decalageV3eNiveau=2;

var delaiAffichage=500;

function activerMenus(idMenuAActiver,vitesseTransitionMenu)
	{
	$('ul#'+idMenuAActiver+' li ul>li:first-child').not('ul#'+idMenuAActiver+' div ul li').addClass('premier');
	$('ul#'+idMenuAActiver+' li ul>li:last-child').not('ul#'+idMenuAActiver+' div ul li').addClass('dernier');
	$('ul#'+idMenuAActiver+' li ul').not('ul#'+idMenuAActiver+' div ul,ul#'+idMenuAActiver+' li.sectionEnCours ul').css('display','block').css('visibility','hidden').each(function(){
		$(this).css('height',$(this).height()+'px')
	});
	
	/*spécifique au site*/
	$('ul#'+idMenuAActiver+' li div').append('<div class="antifloat"></div>')
	$('ul#'+idMenuAActiver+' li div').each(function(){
		$(this).find('>ul').last().css('padding','0 0 0 20px').css('border','none').css('margin-right','0')
	})
	/*spécifique au site*/
	
	$('ul#'+idMenuAActiver+' li a').not('ul#'+idMenuAActiver+' li ul li a,ul#'+idMenuAActiver+' li.sectionEnCours').prepend('<span class="fixPlein"></span>');
	$('ul#'+idMenuAActiver+' li span.fixPlein').each(function(){
		var paddingHaut=parseInt($(this).parent().css('padding-top').substr(0,$(this).parent().css('padding-top').length-2));
		var hauteurLien=$(this).parent().height();
		var hauteurFix=0
		if(jQuery.browser.msie){
			var hauteurFix=(paddingHaut*2)
		}else{
			var hauteurFix=(paddingHaut*2)+hauteurLien
		}
		
		$(this).css('height',hauteurFix+'px');
		$(this).css('width',$(this).parent().outerWidth()+'px');
		})
	$('ul#'+idMenuAActiver+' li ul').not('ul#'+idMenuAActiver+' li div ul,ul#'+idMenuAActiver+' li.sectionEnCours ul').css('display','none').css('visibility','visible');
	
	$('ul#'+idMenuAActiver+' li ul').not('ul#'+idMenuAActiver+' div ul').parent().find('>a').addClass('subfolderstyle')
	
	$('ul#'+idMenuAActiver+' li ul').not('ul#'+idMenuAActiver+' li.sectionEnCours ul').parent().each(function(){
		$(this).find('>a').css('z-index','50');
		$(this).children().not('a').css('z-index','99');
		if($(this).parent().attr('id')==idMenuAActiver){
			//2e niveau
			if($(this).offset().left-decalageH2eNiveau+$(this).children().not('a').outerWidth() < $(window).width()){
				$(this).children().not('a').css('left',(decalageH2eNiveau*-1)+'px');
				}
				else
				{
				var differenceMenus=($(this).outerWidth()-$(this).children().not('a').outerWidth());
				$(this).children().not('a').css('left',(differenceMenus+decalageH2eNiveau)+'px');
				}
			}
			else
			{
			//3e,4e,5e... niveau
			if($(this).offset().left-decalageH2eNiveau+$(this).children().not('a').outerWidth()+$(this).outerWidth() < $(window).width()){
				$(this).children().not('a').css('left',($(this).outerWidth()-decalageH3eNiveau+1)+'px');
				$(this).children().not('a').css('top',decalageV3eNiveau+'px');
				}
				else{
				$(this).children().not('a').css('left',(1+decalageH3eNiveau-$(this).children().not('a').outerWidth())+'px');
				$(this).children().not('a').css('top',decalageV3eNiveau+'px');
				}
			}
		})
	
	
	
	
	//detection sousMenusOuvert
	$('ul#'+idMenuAActiver+' li ul,ul#'+idMenuAActiver+' li div').not('ul#'+idMenuAActiver+' li div ul,ul#'+idMenuAActiver+' li.sectionEnCours ul,ul#'+idMenuAActiver+' li.sectionEnCours div').parent().mouseover(function(){
		$(this).stop(true,true);
		$(this).children().not('a').stop(true,true);
		if($(this).children().not('a').css('display')!='block'){
			$(this).delay(delaiAffichage/2).queue(function(){
			$(this).find('>a').addClass('actif');
			$(this).children().not('a').stop(true,true).attr('style','display:none;visibility:visible;');
			$(this).children().not('a').css('overflow','hidden');
			$(this).children().not('a').clearQueue().slideDown(vitesseTransitionMenu,function(){$(this).css('overflow','visible')});
			
			$(this).siblings('li').not('li.sectionEnCours').each(function(){
				$(this).clearQueue();
					$(this).clearQueue();
					if($(this).children().not('a').length > 0){
						$(this).children().not('a').stop(true,true);
						if($(this).children().not('a').css('display') != 'none'){
							$(this).children().not('a').delay(delaiAffichage/2).queue(function(){
								$(this).parent().css('z-index','50');
								$(this).parent().find('>a').removeClass('actif');
								$(this).dequeue();
							})
							.fadeOut(vitesseTransitionMenu,function(){$(this).attr('style','display:none;visibility:visible;');$(this).clearQueue()});
						}
					}
				})
			
			$(this).css('z-index','99');
			//position d'affichage par rapport au niveau
			if($(this).parent().attr('id')==idMenuAActiver){
				//2e niveau
				if($(this).offset().left-decalageH2eNiveau+$(this).children().not('a').outerWidth() < $(window).width()){
					$(this).children().not('a').css('left',(decalageH2eNiveau*-1)+'px');
					}
					else
					{
					var differenceMenus=($(this).outerWidth()-$(this).children().not('a').outerWidth());
					$(this).children().not('a').css('left',(differenceMenus+decalageH2eNiveau)+'px');
					}
				}else{
				//3e,4e,5e... niveau
				if($(this).offset().left-decalageH2eNiveau+$(this).children().not('a').outerWidth()+$(this).outerWidth() < $(window).width()){
					$(this).children().not('a').css('left',($(this).outerWidth()-decalageH3eNiveau+1)+'px');
					$(this).children().not('a').css('top',decalageV3eNiveau+'px');
					}else{
					$(this).children().not('a').css('left',(1+decalageH3eNiveau-$(this).children().not('a').outerWidth())+'px');
					$(this).children().not('a').css('top',decalageV3eNiveau+'px');
				}
			}
			$(this).dequeue();
			})
		}
	})
	
	$('ul#'+idMenuAActiver+' li ul,ul#'+idMenuAActiver+' li div').not('ul#'+idMenuAActiver+' li div *,ul#'+idMenuAActiver+' li.sectionEnCours ul,ul#'+idMenuAActiver+' li.sectionEnCours div').parent().mouseout(function(){
			$(this).stop(true,true);
			$(this).children().not('a').stop(true,true);
			if($(this).children().not('a').css('display') != 'none'){
				$(this).children().not('a').delay(delaiAffichage/2).queue(function(){
					$(this).parent().css('z-index','50');
					$(this).parent().find('>a').removeClass('actif');
					$(this).dequeue();
				})
				.fadeOut(vitesseTransitionMenu,function(){$(this).attr('style','display:none;visibility:visible;');$(this).clearQueue()});
			}
		})
	}
