$(document).ready( function () {	
	/******** menu haut ************/
	$("ul#menu_haut li.niveau_1").mouseenter(function() {
		$(this).find('ol').show();
		$(this).find('a').addClass('sfover');
	}).mouseleave(function(){$(this).find('ol').hide(); $(this).find('a').removeClass('sfover');});

	// 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")
		}
	);

	$('.img_zoom').live('mouseenter mouseleave', function(event){
		if(event.type == 'mouseenter'){
			$(this).find('span').fadeIn(100);
		}else{
			$(this).find('span').fadeOut(100);
		}
	});
	
	// 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");
		});
	}
	
//========================
//	Autocomplete
//========================
function searchScript(inputString) {
	if(inputString.length > 2)  {
			// Hide the suggestion box.
			$.post("http://www.berceaumagique.com/autocomplete.php", {q: ""+inputString+"", postString: "autoComplete"}, function(data){
				if(data != "")
					{
						$('#resultSearch').show();
						$('#resultSearch').html(data);
					}
				else { $('#resultSearch').hide(); }
			});
			
	} else
	{
		$('#resultSearch').hide();
	}
}

$('#champ_recherche').keyup(function(){
	searchScript($(this).val());
});
	
});
