$(function(){ 
	//Roll Over boutons de formulaires
	//---------------------------------------------
	if($(".formbutton").length>0){
		$(".formbutton").each(function(){
			$(this).hover(
				function(){
					$(this).css({"background-color":"#4b4b4b"});
					$(this).css({"color":"#e5e5e5"});
				},
				function(){
					$(this).css({"background-color":"#e5e5e5"});
					$(this).css({"color":"#535252"});
				}				
			);
		});
	}
	if($(".commons_basicSearchForm form .submitbutton").length>0){
		$(".commons_basicSearchForm form .submitbutton").each(function(){
			$(this).hover(
				function(){
					$(this).css({"background-color":""});
					$(this).css({"color":""});
					$(this).removeClass().addClass("formbutton submitbutton hover");
				},
				function(){
					$(this).css({"background-color":""});
					$(this).css({"color":""});
					$(this).removeClass().addClass("formbutton submitbutton");
				}				
			);
		});
	}
	if($(".navformbutton").length>0){
		$(".navformbutton").each(function(){
			$(this).hover(
				function(){
					$(this).css({"background-color":"#4b4b4b"});
					$(this).css({"color":"#e5e5e5"});
				},
				function(){
					$(this).css({"background-color":"#e5e5e5"});
					$(this).css({"color":"#535252"});
				}				
			);
		});
	}
	//Roll Over liens du menu 1
	//---------------------------------------------
	if($("#header_center .commons_navmenu .level1 .m1").length>0){
		$("#header_center .commons_navmenu .level1 .selected").each(function(){
			$(this).next(".pipe").css({"visibility":"hidden"});
			$(this).prev(".pipe").css({"visibility":"hidden"});
		});
		$("#header_center .commons_navmenu .level1 .m1").each(function(){
			var currentclass = $(this).attr("class");
			$(this).hover(
				function(){
					$(this).next(".pipe").css({"visibility":"hidden"});
					$(this).prev(".pipe").css({"visibility":"hidden"});
				},
				function(){
					if($.trim(currentclass) == 'm1' || $.trim(currentclass) == 'm1 last'){
						//alert(currentclass);
						var nextclass = $(this).next(".pipe").next(".m1").attr("class");
						if($.trim(nextclass) != 'm1 selected' && $.trim(nextclass) != 'm1 selected last'){
							$(this).next(".pipe").css({"visibility":"visible"});
						}
						var prevclass = $(this).prev(".pipe").prev(".m1").attr("class");
						if($.trim(prevclass) != 'm1 selected' && $.trim(prevclass) != 'm1 selected last'){
							$(this).prev(".pipe").css({"visibility":"visible"});
						}
					}else{
						//alert('selected, on laisse caché : [' + currentclass + ']');
					}
				}				
			);
		});
		$("#header_center .commons_navmenu .level1 .m1 .level2").each(function(){
			var parentclass = $(this).parent(".m1").attr("class");
			$(this).hover(
				function(){
					if($.trim(parentclass) == 'm1' || $.trim(parentclass) == 'm1 last'){
						$(this).parent(".m1").addClass("hover");
						$(this).parent(".m1").next(".pipe").css({"visibility":"hidden"});
						$(this).parent(".m1").prev(".pipe").css({"visibility":"hidden"});
					}
				},
				function(){
					if($.trim(parentclass) == 'm1' || $.trim(parentclass) == 'm1 last'){
						$(this).parent(".m1").removeClass("hover");
						var nextparentclass = $(this).parent(".m1").next(".pipe").next(".m1").attr("class");
						if($.trim(nextparentclass) != 'm1 selected' && $.trim(nextparentclass) != 'm1 selected last'){
							$(this).parent(".m1").next(".pipe").css({"visibility":"visible"});
							//alert('[' + $.trim(nextparentclass) + ']');
						}
						var prevparentclass = $(this).parent(".m1").prev(".pipe").prev(".m1").attr("class");
						if($.trim(prevparentclass) != 'm1 selected' && $.trim(prevparentclass) != 'm1 selected last'){
							$(this).parent(".m1").prev(".pipe").css({"visibility":"visible"});
							//alert(prevparentclass);
						}
					}
				}				
			);
		});
		//positionnement du sous-menu
		$("#header_center .commons_navmenu .level1 .m1").each(function(){
			var id = $(this).attr("id");
			var left = document.getElementById(id).offsetLeft;
			$(this).children(".level2").attr("style","left:"+left+"px");
			if($(this).is(".last")){
				var largeur_last_li = $(this).width();
				var largeur_last_ul = $(this).children(".level2").width();
				$(this).children(".level2").attr("style","left:"+(left+largeur_last_li-largeur_last_ul)+"px");
			}
			
		});
	}
	//QuickView news
	//---------------------------------------------
	if($(".newsquickviewer").length>0){
		$(".newsquickview_top").attr({href:"javascript:void(0);"});
		$(".newsquickview_bottom").attr({href:"javascript:void(0);"});
		$(".newsquickview_top").click(function(){
			if($(".newsquickviewer_pos1").prev(".item").length>0){
				//alert('on monte');
				$(".newsquickviewer_pos1").prev(".item").addClass("newsquickviewer_pos1").next(".newsquickviewer_pos1").removeClass("newsquickviewer_pos1");
				$(".newsquickviewer_pos2").prev(".item").addClass("newsquickviewer_pos2").next(".newsquickviewer_pos2").removeClass("newsquickviewer_pos2");
			}
		});
		$(".newsquickview_bottom").click(function(){
			if($(".newsquickviewer_pos2").next(".item").length>0){
				//alert('on descend');
				$(".newsquickviewer_pos2").next(".item").addClass("newsquickviewer_pos2").prev(".newsquickviewer_pos2").removeClass("newsquickviewer_pos2");
				$(".newsquickviewer_pos1").next(".item").addClass("newsquickviewer_pos1").prev(".newsquickviewer_pos1").removeClass("newsquickviewer_pos1");
			}
		});
	}
	//Teasers Services
	//---------------------------------------------
	if($(".promotion_services").length>0){
		$(".tsleft_1_default").hover(function(){
			$(".tsright_default").hide();
			$(".tsright_1").show();
			$(".tsright_2").hide();
			$(".tsright_3").hide();
			$(".tsright_4").hide();
			$(".tsleft_1_default").hide();
			$(".tsleft_1_hover").show();
			$(".tsleft_2_default").show();
			$(".tsleft_2_hover").hide();
			$(".tsleft_3_default").show();
			$(".tsleft_3_hover").hide();
			$(".tsleft_4_default").show();
			$(".tsleft_4_hover").hide();
		},function(){});
		$(".tsleft_2_default").hover(function(){
			$(".tsright_default").hide();
			$(".tsright_1").hide();
			$(".tsright_2").show();
			$(".tsright_3").hide();
			$(".tsright_4").hide();
			$(".tsleft_1_default").show();
			$(".tsleft_1_hover").hide();
			$(".tsleft_2_default").hide();
			$(".tsleft_2_hover").show();
			$(".tsleft_3_default").show();
			$(".tsleft_3_hover").hide();
			$(".tsleft_4_default").show();
			$(".tsleft_4_hover").hide();
		},function(){});
		$(".tsleft_3_default").hover(function(){
			$(".tsright_default").hide();
			$(".tsright_1").hide();
			$(".tsright_2").hide();
			$(".tsright_3").show();
			$(".tsright_4").hide();
			$(".tsleft_1_default").show();
			$(".tsleft_1_hover").hide();
			$(".tsleft_2_default").show();
			$(".tsleft_2_hover").hide();
			$(".tsleft_3_default").hide();
			$(".tsleft_3_hover").show();
			$(".tsleft_4_default").show();
			$(".tsleft_4_hover").hide();
		},function(){});
		$(".tsleft_4_default").hover(function(){
			$(".tsright_default").hide();
			$(".tsright_1").hide();
			$(".tsright_2").hide();
			$(".tsright_3").hide();
			$(".tsright_4").show();
			$(".tsleft_1_default").show();
			$(".tsleft_1_hover").hide();
			$(".tsleft_2_default").show();
			$(".tsleft_2_hover").hide();
			$(".tsleft_3_default").show();
			$(".tsleft_3_hover").hide();
			$(".tsleft_4_default").hide();
			$(".tsleft_4_hover").show();
		},function(){});
	}
	//Onglets Formation
	//---------------------------------------------
	if($(".onglets .onglet").length>0){
		$(".onglets .onglet").each(function(){
			$(this).hover(
				function(){
					if($(this).not(".selected")){
						$(this).addClass("hover");
					}
				},
				function(){
					if($(this).not(".selected")){
						$(this).removeClass("hover");
					}
				}				
			);
			$(this).click(
				function(){
					if($(this).not(".selected")){
						$(".onglets .onglet").each(function(){
							$(this).removeClass("selected");
						});
						$(this).addClass("selected");
					}
				}				
			);
		});
	}
	if($(".onglets .onglet_1").length>0){
		$(".onglets .onglet_1").each(function(){
			$(this).click(function(){
				if($(this).not(".selected")){
					$(".formation_content").each(function(){
						$(this).hide();
					});
					$(".formation_content_1").show();
				}
			});
		});
	}
	if($(".onglets .onglet_2").length>0){
		$(".onglets .onglet_2").each(function(){
			$(this).click(function(){
				if($(this).not(".selected")){
					$(".formation_content").each(function(){
						$(this).hide();
					});
					$(".formation_content_2").show();
				}
			});
		});
	}
	if($(".onglets .onglet_3").length>0){
		$(".onglets .onglet_3").each(function(){
			$(this).click(function(){
				if($(this).not(".selected")){
					$(".formation_content").each(function(){
						$(this).hide();
					});
					$(".formation_content_3").show();
				}
			});
		});
	}
	
	
	
});

/** vide le champs input quand on clique dessus (search)**/
function vider_champs(nom_champs){
  		if(document.getElementById(nom_champs)){
			document.getElementById(nom_champs).value = '';
		}
}
/** survol menu deroulant **/
var toTest = new Array();
for(i = 0 ; i < 10 ; i++){
	toTest[i] = 0;
}
function show(p_elemId, type){
		if(document.getElementById('m2_'+p_elemId)){
			document.getElementById('m2_'+p_elemId).style.display = 'block';
			var m1class = document.getElementById('m1_'+p_elemId).className.replace(/^\s+/g,'').replace(/\s+$/g,'');
			//alert('['+m1class+']');
			if(m1class=='m1 last' || m1class=='m1 hover last'){
				m1class = 'm1 hover last';
			}else{
				m1class = 'm1 hover';
			}
		}
		toTest[p_elemId] ++;		
}
function hide(p_elemId, type){
		setTimeout('hideMenu("'+ p_elemId +'","'+ type +'")', 1);
}
function hideMenu(p_elemId, type){
		toTest[p_elemId] --;
		if(toTest[p_elemId] != 0){
			return;
		}
		if(document.getElementById('m2_'+p_elemId)){
			document.getElementById('m2_'+p_elemId).style.display = 'none';
			var m1class = document.getElementById('m1_'+p_elemId).className.replace(/^\s+/g,'').replace(/\s+$/g,'');
			//alert('['+m1class+']');
			if(m1class=='m1 last' || m1class=='m1 hover last'){
				m1class = 'm1 last';
			}else{
				m1class = 'm1';
			}
		}
}
