/*JS Global PUGET*/

var $j = jQuery.noConflict();

function clearDrops(){
	$j("header nav ul li").removeClass("active");
}

$j(function(){
	
	/*Search field header*/
	$j("#search-field input.text").focus(function(){
		if($j(this).attr("value") == "Rechercher une info produit, une recette..."){
			$j(this).attr("value","");
		}
	});
	$j("#search-field input.text").blur(function(){
		if($j(this).attr("value") == ""){
			$j(this).attr("value","Rechercher une info produit, une recette...");
		}
	});
	
		
	$j("#search-plus input.text").focus(function(){
		if($j(this).attr("value") == "Par ingredient"){
			$j(this).attr("value","");
		}
	});
	$j("#search-plus input.text").blur(function(){
		if($j(this).attr("value") == ""){
			$j(this).attr("value","Par ingredient");
		}
	});
	
	/*Dropdowns menus header*/
	$j("header nav ul li > strong").hover(
		function(){
			if($j(this).parent("li").attr("class") != "disabled"){
				$j("header nav ul li").removeClass("active");
				$j(this).parent("li").addClass("active");
			}
		},
		function(){
		
			$j(".dropdown").mouseleave(function(){
				clearDrops();

			});
			$j("nav").mouseleave(function(){
				clearDrops();

			});
		}
	);
	
	/*Selects Dropdown*/
	$j(".dropdown form p strong").click(function(){
		if($j(this).parent().find("span").is(":visible")){
			$j(this).parent().find("span").hide();
		} else {
			$j(this).parent().find("span").show();
		}
	});	
	
	/*Popups*/
	
	$j("a.videolink").click(function(e){
		e.preventDefault();
		
		thisHeight = $j(document).height();
		thisWidth = $j(document).width();
		
		thisHref = $j(this).attr("href");
		
		$j("#global-overlay").css({opacity:"0", display:"block", height: thisHeight-144}).animate({opacity:"0.8"});
		$j(".overlay").css({top: "200px"});
		$j(thisHref).fadeIn();
	});
	
	
	//IE FIX
	$j(".IE .overlay .close, .IE #question-form .close").click(function(){
		$j("#global-overlay").fadeOut();
		$j(".overlay, #question-form").fadeOut();
		
		if( $j(this).next(".content").find("embed").length > 0 ){
			thisObject = $j(this).next(".content").clone(true);
			$j(this).next(".content").remove();
			$j(this).parent().append(thisObject);
		} 
	});
	
	$j("a.login").click(function(e){
		e.preventDefault();
		
		thisHeight = $j(document).height() - 144;
		thisWidth = $j(document).width();
		
		thisHref = $j(this).attr("href");
		$j("#global-overlay").css({opacity:"0", display:"block", height: thisHeight }).animate({opacity:"0.8"});
		$j(".overlay").css({top: "200px"});
		$j(thisHref).fadeIn();
	});
	
	$j("a.formlink").click(function(e){
		e.preventDefault();
		
		thisHeight = $j(document).height();
		thisWidth = $j(document).width();
		
		thisHref = $j(this).attr("href");
		$j("#global-overlay").css({opacity:"0", display:"block", height: thisHeight}).animate({opacity:"0.8"});
		$j(".overlay").css({top: "200px"});
		$j(thisHref).fadeIn();
	});
	
	$j(".overlay .close, .overlayForm .close, .overlayLogin .close, #question-form .close,#send-friend-form .close,#gift-form .close").click(function(){
		$j("#global-overlay").fadeOut();
		$j(".overlay, .overlayForm, .overlayLogin, #question-form,#send-friend-form,#gift-form").fadeOut();
	});
	
	$j("#question-form .closeEnd").click(function(){
		$j("#global-overlay").fadeOut();
		$j(".overlay, .overlayForm, .overlayLogin, #question-form,#send-friend-form,#gift-form").fadeOut('slow', function() {
			document.getElementById("contactoFormWebID").style.display = "none";
			document.getElementById("contactoFormProdID").style.display = "none";
			document.getElementById("msgReturn").style.display = "none";
			document.getElementById("contactoFormID").style.display = "block";
			document.getElementById("contactoFormID").reset();
			document.getElementById("contactoFormWebID").reset();
			document.getElementById("contactoFormProdID").reset();
			$j('#msgReturn').html("");
		});
	});
	
	/*Login*/
	/*$j(".login-box .login").click(function(e){
		e.preventDefault();
		$j(".login-box").removeClass("login-active");
		$j(".login-box2").addClass("login-active");
	});
	
	$j(".login-box2 .close").click(function(e){
		e.preventDefault();
		$j(".login-box2").removeClass("login-active");
		$j(".login-box").addClass("login-active");
	});*/
	
	/*Question form*/
	$j("#question-form .content strong").click(function(){
		$j(this).next("span.select").toggleClass("active");
	});
	
	$j("#question-form .content .select em").click(function(){
		$j(this).parent().prev("strong").text($j(this).text());
		$j(this).parent("span.select").toggleClass("active");
	});


});





function redirectPage(id, page)
{
	
	if(page != "null")
	window.location = page;
}

 function loadBlueStreak(id) {
  bscounter = new Image();
  bscounter.src = "http://s0b.bluestreak.com/ix.e?bb&t=" + id;
 } 
