$(document).ready( function () {
	// On cache les sous-menus sauf ceux qui contiennent dans leur classe "current2" ou "current3" :
	/******** menu gauche ************/
	/*$("ul#menu_nav_gauche ul.conteneur_niveau_2:not('li.ouvert1 > div.menuNavG_centre > ul.conteneur_niveau_2'),ul#menu_nav_gauche ul.conteneur_niveau_3:not('li.ouvert2 > ul.conteneur_niveau_3')").hide();*/
	
	//$("ul#menu_nav_gauche li.ouvert1 > div.menuNavG_centre > ul.conteneur_niveau_2,ul#menu_nav_gauche li.ouvert2 > ul.conteneur_niveau_3").show();
	
	/******** menu haut ************/
	//$("ul#menu_haut ul.conteneur_niveau_2").hide();
	
	TIMER = 0; //délais pour l'action au survol, en ms
	TIMER2 = 150; //délais fermeture
	waitToOpen2 ='';
	$("ul#menu_haut li.niveau_1").hover( 
		function(){
			
			
			
			if ($(this).children("ul#menu_haut ol.conteneur_niveau_2:visible").length != 0) //si on rentre dans un menu ouvert, c'est surement qu'on a "dérapé" juste avant alors on stop tout pour que rien ne soit modifié
			{
				
				clearTimeout(waitToClose2);
			}
			else
			{
				overClosed2 = ($(this)); //on recupere l'element actuel avec this, car dans la fonction setTimeout this est différent
				waitToOpen2 = setTimeout(function () {			
					$("ul#menu_haut li.niveau_1 ol.conteneur_niveau_2").slideUp("fast");
					
					
					
					
						
						$(overClosed2).children("ul#menu_haut a.overkeep").addClass("sfover");
						
					
					
					$(overClosed2).children("ul#menu_haut ol.conteneur_niveau_2").slideDown("fast");
				},TIMER);
			}
		},function(){
			if ($(this).children("ul#menu_haut ol.conteneur_niveau_2:visible").length != 0) //sortie menu ouvert
			{
				outOpened2 = ($(this));
				$(outOpened2).children("ul#menu_haut a.overkeep").removeClass("sfover");
				waitToClose2 = setTimeout(function () {
													
					
					$(outOpened2).children("ul#menu_haut ol.conteneur_niveau_2").slideUp("fast");
					
					
				},TIMER2);
			}
			else
			{
				clearTimeout(waitToOpen2);
			}
		}
	);
	
	
	

	
	// hack pour ie6 pou chacher les select qui reste au dessus du menu qui apparait
	$("ul#menu_haut").hover(
		function(){
			if (typeof document.body.style.maxHeight == "undefined") // cas ie6
				$("div#new_recherche select").hide();
		},function(){
			if (typeof document.body.style.maxHeight == "undefined")
				$("div#new_recherche select").show();
		}
	);
	
	// affichage de l'image survolée en grand, et conservation quand elle est cliquée, page produit
	$("div#images_secondaires img:not('div#images_secondaires img.bonus')").mouseover(
		function(){
			img = $("div#image_principale img:visible")['0'].id;
			id = img.substring(5); /* on garde l'id de l'image qui doit rester */
			
			$("div#image_principale img").hide();
			$("div#image_principale img#prin_"+this.id).show();
			$(this).bind('mouseout', // on ajoute l'evenement
				function(){
					$("div#image_principale img").hide();
					$("div#image_principale img#prin_"+id).show();
				}
			)
		}
	).click(
		function(){
			$("div#image_principale img").hide();
			$("div#image_principale img#prin_"+this.id).show();
			$(this).unbind('mouseout'); // on enlève l'evenement car si on a cliqué sur une image, on veut pas de mouseout sur le coup
		}
	);
	
	// affichage du contenu du panier, header
	$("div.panier_rempli").hover(function(){
		$("div#contenu_panier").fadeIn("fast")
		},function(){
		$("div#contenu_panier").fadeOut("fast")
		}
	);
	
	//affichage du contenu de la liste, header
	$("div.liste_rempli").hover(function(){
		$("div#contenu_liste").fadeIn("fast")
		},function(){
		$("div#contenu_liste").fadeOut("fast")
		}
	);
	/*
	// affichage en gros des images produits, quand on est dans un rayon
	if (typeof document.body.style.maxHeight == "undefined") //ie6 n'aime pas le fondu
	{
		$(".img_zoom").hover(function(){
			$(this).children("span").show();
		},function(){
			$(this).children("span").hide();
		});
	}
	else
	{
		$(".img_zoom").hover(function(){
			$(this).children("span").fadeIn("fast");
		},function(){
			$(this).children("span").fadeOut("fast");
		});
	}
	*/
	
	 
	
	// affichage en gros des images produits, avec livequery, pour que ça marche après un chargement ajax, quand on est dans un rayon
	if (typeof document.body.style.maxHeight == "undefined") //ie6 n'aime pas le fondu
	{
		$('.img_zoom').livequery(function(){ 
		// use the helper function hover to bind a mouseover and mouseout event 
			$(this) 
				.hover(function() { 
					$(this).children("span").show();
				}, function() { 
					$(this).children("span").hide();
				}); 
		}, function() { 
			// unbind the mouseover and mouseout events 
			$(this) 
				.unbind('mouseover') 
				.unbind('mouseout'); 
		});
	}
	else
	{
		$('.img_zoom').livequery(function(){ 
		// use the helper function hover to bind a mouseover and mouseout event 
			$(this) 
				.hover(function() { 
					$(this).children("span").fadeIn("fast");
				}, function() { 
					$(this).children("span").fadeOut("fast");
				}); 
		}, function() { 
			// unbind the mouseover and mouseout events 
			$(this) 
				.unbind('mouseover') 
				.unbind('mouseout'); 
		});
	}
	
	
	
	
	
	
	// affichage en des images pour les top idées cadeaux, menu droit
	if (typeof document.body.style.maxHeight == "undefined")
	{
		$(".img_zoom2").hover(function(){
			$(this).children("span.topid").show();
		},function(){
			$(this).children("span.topid").hide();
		});
	}
	else
	{
		$(".img_zoom2").hover(function(){
			$(this).children("span.topid").fadeIn("fast");
		},function(){
			$(this).children("span.topid").fadeOut("fast");
		});
	}
	
	//autocomplétion de la recherche, header
	$("#champ_recherche").autocomplete("autocomplete.php", {
		minChars:2,
		width:209,
		max:20,
		scrollHeight:1000,
		matchContains:true,
	
	
		selectFirst:false,
		delay:150
	}).result(function(){
			$('#recherche').submit();
	});
	
	// diapo animé des marques menu gauche
	$("#diapo_marques").cycle({
		fx: 'fade',
		speed: 1000,
		timeout: 3500,
		pause: 1
	});
	
	// diapo bannière animée accueil
	$("#diapo").cycle({
		fx: 'fade',
		speed: 1000,
		timeout: 5000,
		pause: 1,
		pager:'#boutons_diapo',
		pauseOnPagerHover:1,
		pause:1,
		pagerEvent: 'mouseover',
		pagerAnchorBuilder: function(idx, slide) { 
			return '#boutons_diapo a:eq(' + idx + ')'; 
		}
	});
	//enleve le cadre de selection au moment du click, car il y a un gros text-indent qui implique un gros cadre
	$('#boutons_diapo a').click(function(){
		$(this).blur();
	});
	
} ) ;
