﻿// JavaScript Document

//Test Modification ptsan 09/07/08

$('document').ready(function(){
	nav_fond_de_sauce();
	addClassAndCarouselToHP();
	selectList();
	listCarousel();
	displayFunctions();
	
	tabNav();
	intiCoaching();
	initShowLayer();
	initFlashNav();
	initShowValue();
	setPopinEvent();
	dossier();
	closePopup();
	openPopup();
	showItem();
	popUpShow();
	
	/* NAVIGATION GAUCHE dossier maggi --- */
	$('.dossierLinkFlash').click(function(){
		if($(this).parent().attr('class')!='opened'){
			$(this).parent().addClass('opened');
		}else{
			$(this).parent().removeClass('opened');
		}
		return false;	
	});
	
	eventsFicheProduit();
	eventsThumbs();
	AjusterOngletFicheRecettes();
	navGuideRecettes();
	loadImageFlow();
	loadcarousel();
	
	carrouselHomePage();
	carrouselBouillon();
	carrouselfondSauce();
	carrouselPoisson();
	carrouselCourtBouillon();
	afficher_note();
	// la popin conformation de la page  [games/2011-Kub-Or-Pack/participation-vote.aspx]
	//if($('#conformation_popin').length)
	
	//initIntersticiel("/Common/Templates/AlertInterstitial.aspx", "300", "250", "ADEFINIR", "0.6", "#000");
	if($('.discover_pdt .stdNavTab').length)
	ongletPapillotes();
	courgettes();
	
	//popin Promo
	popinPromoEvent();
	
	
	// popin Echantillons
	$('#page').after($('#reglement_popin'));
	$('.regl').bind('click', function(){
		ShowReglement();
		if (!$('.jScrollPaneContainer').length) $('.reglement_inner').jScrollPane({showArrows:true});
		return false;
	});
	$('#close,#overlay').live('click', function(){
		$('#overlay').remove();
		$('#reglement_popin').hide();
		return false;
	});
	
	 if($('.std_qst').length) questionsDonneesPersonnelles();
	 
	
	
});


function questionsDonneesPersonnelles(){
	 $('.questionContent').hide();
	$('.questionLink').click(function(){
		
		var hiddenDiv = $(this).parents('.std_qst').next('.questionContent');
		if (!hiddenDiv.is(':visible')) {
			
			$('.questionContent').hide();
			hiddenDiv.slideDown('slow');
		}else{
			hiddenDiv.slideUp('slow');
			
		}
		return false;
	});
}
function courgettes(){
	if($('.incontournables, .tartes_terrines, .star_fetes').length){
		var instanceOne = new ImageFlow();
		carrouselImageFlow(instanceOne, 'carrousel_coverflow');
	}
}
	//	survole sur les liens de la page [je-fais-quoi-avec/fond-de-sauce-semaine.aspx]
function nav_fond_de_sauce(){
	if($('.fond_sauce_semaine').length){
		$('.fond_sauce_semaine .png').mouseover(function(){
			var rel = $(this).attr('rel');
			$('.visu',$(this).parents('.box')).attr('src','/recettes/Img/'+rel+'.jpg.ashx?w=244');
		});
	}
}

function afficher_note() {
	$('.stdNavTab .onglet2').click(function(){
		$('.discover_pdt .mention2').show();
		$('.discover_pdt .mention1').hide();
	})
	$('.stdNavTab .onglet1').click(function(){
		$('.discover_pdt .mention1').show();
		$('.discover_pdt .mention2').hide();
	})
	return false;
}

function loadcarousel(){
	/******* [bouillon_vegetal_festives] initialisation de la carrousel*******/
	if($('.bouillon_vegetal_festives').length){
		var instanceOne = new ImageFlow();
		var instanceOne2 = new ImageFlow();
		carrouselImageFlow(instanceOne, 'carrousel_coverflow');
		carrouselImageFlow(instanceOne2, 'carrousel_coverflow2');
	}
	
	return false;
}

function addClassAndCarouselToHP(){
	if($('.hp-maggi').length){
		$('#page').addClass('page-home-maggi');
	}
	if($('.carouselList-home').length){
		if($('.productCarousel').length){
			/*$(".productCarousel").append('<div class="jcarousel-prev jcarousel-prev-horizontal"></div><div class="jcarousel-next jcarousel-next-horizontal"></div>');*//* Commented By Aissa*/
			$('.carouselList-home li a').live('click',function(){
				window.location.href = $(this).attr('href');
			});
			$(".productCarousel").jCarouselLite({
				auto: true,
				speed: 1000,
				timeout: 2000,
				visible: 1
				//btnPause: $('.carouselList-home li a'),
				/*btnNext: $('.carouselList-home li a')*/
				
			});
		}
	}
}

function AjusterOngletFicheRecettes(){
	var nbOnglets = $('.ongletFicheRecettes .stdNavTab li').length;
	switch(nbOnglets){
		case 1: $('#stdOthersRecettes .stdNavTab').addClass('oneOnglet');break;
		case 2: $('#stdOthersRecettes .stdNavTab').addClass('twoOnglet');break;
		case 3: $('#stdOthersRecettes .stdNavTab').addClass('threeOnglet');break;
		case 4: $('#stdOthersRecettes .stdNavTab').addClass('fourOnglet');break;
	}
}

function navGuideRecettes(){
	$('.header-guide-recettes li a').click(function(){
		$('.header-guide-recettes li').removeClass('active');
		$(this).parent('li').addClass('active');
		var indexMenu = $('.header-guide-recettes li a').index($(this));
		$('.recettes-items .recettes-item').hide();
		$('.recettes-items .recettes-item').eq(indexMenu).show();
		return false;
	});
}

function eventsThumbs(){
	if($('.list_thumbs').length){
		
		$('.list_thumbs a').click(function(){
			var index = $('.list_thumbs a').index($(this));
			var img = $(this).attr('href');
			var link = $(this).attr('rel');
			var recetteName = $('img', $(this).parents('li')).attr('alt');
			
			$('.big_thumb img').attr('src',img).attr('alt',recetteName);
			$('.big_thumb a').attr('href', link);
			
			$('.top5Recettes div h2').hide().eq(index).show();
			return false;
		})
	}
}

/* Create ImageFlow instances when the DOM structure has been loaded */
function loadImageFlow(){
	if($('.carrousel_arome').length){
		var instanceOne = new ImageFlow();
		carrouselImageFlow(instanceOne, 'carrousel_coverflow');
	}
}


/* carrouselPoisson */
function carrouselPoisson(){
	if($('.carrousel_poisson').length){
		var instanceOne = new ImageFlow();
		carrouselImageFlow(instanceOne, 'carrousel_coverflow');
	}
}

/* carrousels Court Bouillon */
function carrouselCourtBouillon(){
	if($('.carrousel_court_bouillon').length){
		var instanceOne = new ImageFlow();
		carrouselImageFlow(instanceOne, 'carrousel_coverflow');
	}
	if($('.simple_carrousel_court_bouillon').length){
		$(".simple_carrousel_court_bouillon").jCarouselLite({
			speed: 800,
			visible: 3,
			btnNext: $('.jcarousel-next'),
			btnPrev: $('.jcarousel-prev')
		});
	}
}

function carrouselImageFlow(instanceOne, ID){
	instanceOne.init({
		ImageFlowID:ID,
		circular: true,
		reflections: false,
		reflectionP: 1.6,
		slider: true,
		xStep: 225,
		imageFocusM: 1.5,
		startID: 3,
		slideshow: true,
		slideshowAutoplay: true,
		slideshowSpeed: 4000,
		buttons: true,
		imagesHeight: 0.28 });
}

function carrouselHomePage(){
	if($('.je-fais-quoi-avec .carouselHomePage').length){
		$(".carouselHomePage").jCarouselLite({
			speed: 800,
			visible: 5,
			btnNext: $('.jcarousel-next'),
			btnPrev: $('.jcarousel-prev')
		});
		
		$('#mycarousel').pngFix();
	}
}

function carrouselBouillon(){
	if($('.bouillon-recettes .carousel').length){
		$(".bouillon-recettes .carousel").jCarouselLite({
			speed: 800,
			visible: 3,
			btnNext: $('.jcarousel-next'),
			btnPrev: $('.jcarousel-prev')
		});
	}
}
function carrouselfondSauce(){
	if($('.fond_sauce_semaine .carousel').length){
		$(".fond_sauce_semaine .carousel").jCarouselLite({
			speed: 800,
			visible: 3,
			btnNext: $('.jcarousel-next'),
			btnPrev: $('.jcarousel-prev')
		});
	}
}
function eventsFicheProduit(){
	if($('.list_linkRecettes').length){
		$('.list_linkRecettes').hide();
	}
	
	$(".link_moreRectte").toggle(
	  function(){
		$('.list_linkRecettes').show();
	  },
	  function(){
		$('.list_linkRecettes').hide();
	  }
	);
}

/* Valeur des imputs */
function initShowValue(){
	inputValue(".valueMail","Votre E-mail");
	inputValue(".valuePass","Votre mot de passe");
}

/* fonction generique de test d'input */

function inputValue(input,valueField){
	$(input).each(function(){
		$(this).click(function(){
			if($(this).attr("value") == valueField){
				this.value = "";
			}		 
		});
		$(this).blur(function(){
			if($(this).attr("value") == ""){
				this.value = valueField;
			}							  
		});
	});
}

/* Flash Saga MAGGI */
function initFlashNav(){
	if($("#maggiHistoryFlash").length){
		swfobject.embedSWF("/App_Themes/Common/swf/maggi_saga.swf", "maggiHistoryFlash", "640", "540", "8.0.0", "/App_Themes/Common/swf/expressInstall.swf");	
		
		$("#navigation a.sagaLinkFlash").each(function(i){
			$(this).click(function(){
				$("#maggiHistoryFlash")[0].showCategory(i+1);
				$(this).parent("li").siblings().removeClass("active");
				$(this).parent("li").addClass("active");
				return false;
		   });
		});
	}
}

function categoryChanged(index){
	var listLinkSaga = $("#navigation a.sagaLinkFlash");
	$(listLinkSaga[index-1]).parent("li").siblings().removeClass("active");
	$(listLinkSaga[index-1]).parent("li").addClass("active");
}

/* ADD video */
function addVideo(idDiv, urlImg, urlFlv ){

	var flash = $("#"+idDiv);		
	if (flash.length){
		var flashvars = {
			confFile: "/App_Themes/Common/xml/conf.xml",
			siteMainFile: "/App_Themes/Common/swf/player.swf",
			preview: urlImg,
			media: urlFlv
		};
		
		var params = {
		  allowScriptAccess: "always",
		  wmode: "transparent"
		};
		
		var attributes = {};
		
		swfobject.embedSWF("/App_Themes/Common/swf/loader.swf", idDiv , "367", "290", "8.0.0", "/App_Themes/Common/swf/expressInstall.swf", flashvars, params, attributes);
	}	
}
/* Flash video */
function flashRecipe(urlImg, urlFlv ){

	var flashRecipeBlock = $("#flashRecipe");
	if (flashRecipeBlock.length){
		var flashvars = {
			confFile: "/App_Themes/Common/xml/conf.xml",
			siteMainFile: "/App_Themes/Common/swf/player.swf",
			preview: urlImg,
			media: urlFlv
		};
		
		var params = {
		  allowScriptAccess: "always",
		  wmode: "transparent"
		};
		
		var attributes = {};
		
		swfobject.embedSWF("/App_Themes/Common/swf/loader.swf", "flashRecipe", "367", "290", "8.0.0", "/App_Themes/Common/swf/expressInstall.swf", flashvars, params, attributes);
	}	
}
/* Flash video Bouillons */
function flashBouillons(urlImg, urlFlv ,id){

	var flashRecipeBlock = $("#"+id);
	if (flashRecipeBlock.length){
		var flashvars = {
			confFile: "/App_Themes/Common/xml/conf.xml",
			siteMainFile: "/App_Themes/Common/swf/player.swf",
			preview: urlImg,
			media: urlFlv
		};
		
		var params = {
		  allowScriptAccess: "always"
		};
		
		var attributes = {};
		
		swfobject.embedSWF("/App_Themes/Common/swf/loader.swf", id, "367", "290", "8.0.0", "/App_Themes/Common/swf/expressInstall.swf", flashvars, params, attributes);
	}	
}

/* transformation de listes en selects */
function selectList(){
	$(".selectList").each(function(){
		var selectTxt = '<select><option selected="selected">'+$(this).find(".titleSelect").html()+'</option>';
		$(this).find("a").each(function(){
			 selectTxt += '<option value="'+$(this).attr("href")+'">'+$(this).html()+'</option>';
		});
		$(this).html(selectTxt);
		var temp=$(this).parent();
			
		if(temp.attr('id')=="footer"){
				
			$(this).find("select").change(function(){
				window.open($(this).find("option")[this.selectedIndex].value);
			});
		}else{
			//alert("---");
			$(this).find("select").change(function(){
				//alert("--- "+$(this).parent().parent().parent().find("a.btnOK").attr("href",$(this).find("option")[this.selectedIndex].value));
				if(this.selectedIndex==0){
					$(this).parent().parent().parent().find("a.btnOK").attr("href","");
				}else{
					$(this).parent().parent().parent().find("a.btnOK").attr("href",$(this).find("option")[this.selectedIndex].value);
				}
			});
			
			
		}
		
	});
}

/* Carrousel */
function listCarousel(){
	
	if($('.carouselList').length){
		if($('.carrousel_nos_pubs').length){
			$(".carrousel_nos_pubs").jcarousel({
				scroll: 3,
				wrap:'last'
			});
		}
		if($('#video_template').length){
			$("#video_template").jcarousel({
				scroll: 3,
				wrap:'last'
			});
		}
		if($('.videoCarousel').length){
			$("#videos_carousel").jcarousel({
				scroll: 3,
				wrap:'last'
			});
		}
		if($('.productCarousel').length){
			if($('#carrouselPartenaires').length){
				$("#carrouselPartenaires").jcarousel({
					scroll: 3,
					wrap:'last'
				});
			}
			if($('#carrouselCatalogProduit').length){
				$("#carrouselCatalogProduit").jCarouselLite({
					speed: 800,
					visible: 3,
					btnNext: $('.next'),
					btnPrev: $('.prev')
				});
			}
			if($('.practicalCarousel').length){
				var initNumber = 1;
				$('.carouselList li').each(function(i){
					if($(this).hasClass("active")){
						initNumber = i;
					}
				});
				$(".productCarousel").jcarousel({
					scroll: 1,
					wrap:'last'
				});
			}
		}
	}
	
}

/* Affichage des boutons d'impressions */
function displayFunctions(){
	if($(".printFunctionBlock").length){
		$(".printFunctionBlock li .link_sendToFriend").after("<a href=\"#\" class='link_print'><img src=\"/App_Themes/Common/img/link_printRecipe2.gif\" alt=\"Imprimer la recette\" /></a>");
	}
	
	if($("#coachingContainer").length){
		$("#coachingContainer").prepend("<p class=\"linkPrintContainer print\"><a href=\"#\"><img src=\"/App_Themes/Common/img/coaching/profil/link_printFile.gif\" alt=\"Imprimer le dossier\" /></a></p>");
		$("#coachingContainer").prepend("<p class=\"linkPrintContainer linkConseiller\"><a href=\"/coaching-culinaire/envoi-a-un-ami.aspx\"><img src=\"/App_Themes/Common/img/coaching/profil/link_conseiller.gif\" alt=\"Conseiller ce coaching à un ami \" /></a></p>");
	}
	
	if($(".printFunctionPdtBlock").length){
		$(".printFunctionPdtBlock .sendToFriend").after("<li class=\"print\"><a href=\"#\"><img src=\"/App_Themes/Common/img/print_pdt.gif\" alt=\"Imprimer la fiche produit\" /></a></li>");
	
	}
	$(".link_print, .print").click(function(){
		window.print();
   });
}

function addCaroussel(){
	if(!$('.jcarousel-container').length){
		$('.carousel_fiche_produit ul').jcarousel({
			scroll: 3,
			wrap:'last'
		});
	}
}
/* Navigation par onglets */
function tabNav(){

	/****** variables utils pour [dossier-salades-tartes-terrines.aspx] *****/
		var clickOnglet2 = false, clickOnglet3 = false;
	/*****************/
	
	initNavTab();
	$(".stdNavTab li").removeClass("active");
	$(".stdContentTab .layerTab").hide();
	
	$(".stdNavTab li:first-child").addClass("active");
	$(".stdContentTab .layerTab:first-child").show();
	
	if($('.carousel_fiche_produit').length){
		setTimeout('addCaroussel()',100);
	}
	
	/******* [dossier-salades-tartes-terrines.aspx] initialisation des carrousels du 1er onglet *******/
		if($('#content.dossier-salades').length){
			var instanceOne = new ImageFlow();
			carrouselImageFlow(instanceOne, 'carrousel_coverflow');
			var instanceOne2 = new ImageFlow();
			carrouselImageFlow(instanceOne2, 'carrousel_coverflow2');
			var instanceOne3 = new ImageFlow();
			carrouselImageFlow(instanceOne3, 'carrousel_coverflow3');
		}
	/******* [dossier-detox.aspx] initialisation des carrousels du 1er onglet *******/
		if($('#content.dossierdetox').length){
			var instanceOne = new ImageFlow();
			carrouselImageFlow(instanceOne, 'carrousel_coverflow');
			var instanceOne2 = new ImageFlow();
			carrouselImageFlow(instanceOne2, 'carrousel_coverflow2');
		}
	/***********************************************/
	$(".stdNavTab li a").unbind("click");
	
	$(".stdNavTab li a").bind("click",function(){
		
		var linkTab = $(this).attr("href").split("#");
		$(".stdNavTab li").removeClass("active");
		
		/******* [dossier-salades-tartes-terrines.aspx] initialisation exceptionnel pour satisfaire IE6 *******/
			if($('#content.dossier-salades').length || $('#content.dossierdetox').length){
				$(".stdContentTab .layerTab").show();
				setTimeout(function(){
					$(".stdContentTab .layerTab").hide();
					$("#"+linkTab[1]).show();
				}, 50);
			}else{
		/**************************/
			$(".stdContentTab .layerTab").hide();
			$("#"+linkTab[1]).show();
			}
		$(this).parent("li").addClass("active");
		
		/******* [dossier-salades-tartes-terrines.aspx] chargement des carrousels en fonction des onglets *******/
			if($('#content.dossier-salades').length){
				if(linkTab[1] == 'onglet2' && clickOnglet2 == false){
					var instanceOne4 = new ImageFlow();
					carrouselImageFlow(instanceOne4, 'carrousel_coverflow4');
					clickOnglet2 = true;
				}
				if(linkTab[1] == 'onglet3' && clickOnglet3 == false){
					var instanceOne5 = new ImageFlow();
					carrouselImageFlow(instanceOne5, 'carrousel_coverflow5');
					var instanceOne6 = new ImageFlow();
					carrouselImageFlow(instanceOne6, 'carrousel_coverflow6');
					clickOnglet3 = true;
				}
			}
			if($('#content.dossierdetox').length){
				if(linkTab[1] == 'onglet2' && clickOnglet2 == false){
					var instanceOne3 = new ImageFlow();
					carrouselImageFlow(instanceOne3, 'carrousel_coverflow3');
					clickOnglet2 = true;
				}
			}
		/******* [dossier_diabete.aspx] initialisation de la carrousel du 3ème onglet *******/
			if($('.dossier_diabete').length){
				if(linkTab[1] == 'onglet3' && clickOnglet2 == false){
					var instanceOne = new ImageFlow();
					var instanceOne2 = new ImageFlow();
					carrouselImageFlow(instanceOne, 'carrousel_coverflow');
					carrouselImageFlow(instanceOne2, 'carrousel_coverflow2');
					clickOnglet2 = true;
				}
			}
				/******* [bouillon_vegetal_festives] initialisation de la carrousel*******/
			if($('.bouillon_vegetal_festives').length){
				var instanceOne = new ImageFlow();
				var instanceOne2 = new ImageFlow();
				carrouselImageFlow(instanceOne, 'carrousel_coverflow');
				carrouselImageFlow(instanceOne2, 'carrousel_coverflow2');
			}
			
		return false;
		
	});
		
	initWidthOfNav() // juste pour la page => videoMaggi
}


function initNavTab(){
	if(!$('#stdOthersRecettes').length){
		$('.stdContentTab').before("<ul class='stdNavTab'></ul>");
	}
	
	$('.stdContentTab .tabTitle').each(function(i){
		var idBlock = "#"+$(this).parent().parent().attr("id");
		var idBlockitems = $(this).parent().parent().attr("id");
		
		$('.stdNavTab').append("<li><a href='"+idBlock+"'><span class='"+idBlockitems+"'>"+$(this).html()+"</span></a></li>"); 
		$(this).addClass("displayTitle");
	});	
	
}
/*********** Ancienne forme du questionnaire coaching avec une question par page ***********

function intiCoaching(){
	var contentCoaching = $(".listQuestionsCoaching");
	if (contentCoaching.length){
		$(".listQuestionsCoaching .errorMsg").hide();
		$(".listQuestionsCoaching .questionBlock").hide();
		$(".listQuestionsCoaching #question1").show();
		formCoaching();
	}
}

function formCoaching(){
	$(".listQuestionsCoaching .previousLink a").click(function(){
		var linkPrevious = $(this).attr("href");
		$(".listQuestionsCoaching .questionBlock").hide();
		$(linkPrevious).show();
		return false;
	});
	$(".listQuestionsCoaching .nextLink a").click(function(){
		var inputQuestion = $(this).parent().parent().parent().find("input[@type=radio]");
		if(inputQuestion.is("[@checked]")){
			var linkNext = $(this).attr("href");
			$(".listQuestionsCoaching .questionBlock").hide();
			$(".listQuestionsCoaching .errorMsg").hide();
			$(linkNext).show();
		}
		else{
			$(this).parent().parent().siblings(".errorMsg").show();		
		}
		return false;
	});
	$(".listQuestionsCoaching .validLink input").click(function(){
		var inputQuestion = $(this).parent().parent().parent().find("input[@type=radio]");
		if(inputQuestion.is("[@checked]")){
			$(".listQuestionsCoaching .errorMsg").hide();	
		}
		else{
			$(this).parent().parent().siblings(".errorMsg").show();
			return false;
		}
	});
}
	*******************************************************************/
/*********** Le questionnaire coaching avec 5 questions par page ***********/
function intiCoaching(){
	var contentCoaching = $(".listQuestionsCoaching");
	if (contentCoaching.length){
		$(".listQuestionsCoaching .errorMsg").hide();
		$(".listQuestionsCoaching .questionBlock").hide();
		$(".listQuestionsCoaching .first5Qestions").show();
		formCoaching();
	}
}


function formCoaching(){
	$(".listQuestionsCoaching .previousLink a").click(function(){
		var linkPrevious = $(this).attr("href");
		$(".listQuestionsCoaching .questionBlock").hide();
		$(linkPrevious).show();
		window.scrollTo(0,200);
		return false;
	});
	$(".listQuestionsCoaching .nextLink a").click(function(){
		$(".listQuestionsCoaching .errorMsg").hide();
		var radioChecked = validRadio('.first5Qestions');
		if(radioChecked == 5){
			var linkNext = $(this).attr("href");
			$(".listQuestionsCoaching .questionBlock").hide();
			$(".listQuestionsCoaching .errorMsg").hide();
			$(linkNext).show();
			window.scrollTo(0,200);
		}
		return false;
	});
	$(".listQuestionsCoaching .validLink input").click(function(){
		$(".listQuestionsCoaching .errorMsg").hide();
		var radioChecked = validRadio('.second5Qestions');
		if(radioChecked == 5){
			$(".listQuestionsCoaching .errorMsg").hide();
		}else return false;
	});
}

function validRadio(blockRadio){
	var radioChecked = 0;
	$(blockRadio).each(function(){
		var inputQuestion = $(this).find("input[type=radio]");
		if(inputQuestion.is(":checked")){
			radioChecked += 1;
		}else $('.errorMsg', $(this)).show();
	});
	return radioChecked;
}

	/*******************************************************************/

function initShowLayer(){
	$('.showInfos').each(function(){
		var blockDisplay = $(this).attr("href");
		hideLayer(blockDisplay);
		
		$(this).click(function(){
			if($(blockDisplay).css("display") == "none" ){
				$(blockDisplay).show();
				if($(this).parent().hasClass("displayLink")){
					$(this).addClass("active");
				}
			}
			else{
				$(blockDisplay).hide();
				if($(this).parent().hasClass("displayLink")){
					$(this).removeClass("active");
				}
			}
			return false;
			
		});
	});
}

function hideLayer(blockHide){
	$(blockHide).addClass("hideBlock");
}

// INFOBULLE
//* Permet d'ajouter ou de supprimer un vnement par objet dans la page */
//~ http://www.quirksmode.org/blog/archives/2005/10/_and_the_winner_1.html

function addEvent( obj, type, fn )
{
	if (obj.addEventListener)
		obj.addEventListener( type, fn, false );
	else if (obj.attachEvent)
	{
		obj["e"+type+fn] = fn;
		obj[type+fn] = function() { obj["e"+type+fn]( window.event ); }
		obj.attachEvent( "on"+type, obj[type+fn] );
	}
}
/* */

var idAnchor    = 'wfa';
var idClose     = 'wfclose';
var idInfobulle = 'wfinfobulle';

function inverseDisplayPresente() {
  if(document.getElementById(idInfobulle).style.display != 'block' ) {
    document.getElementById(idInfobulle).style.display = 'block';
  }
  else {
    document.getElementById(idInfobulle).style.display = 'none';
  }
}

function launch() {
  if(document.getElementById(idInfobulle)) {
      document.getElementById(idInfobulle).style.display = 'none';
  }
  if(document.getElementById(idAnchor)) {
      document.getElementById(idAnchor).setAttribute('href','javascript:inverseDisplayPresente();');
  }
  if(document.getElementById(idClose)) {
      document.getElementById(idClose).setAttribute('href','javascript:inverseDisplayPresente();');
  }
  if($('#page').hasClass('page-home-maggi')) $('#navigation #wfinfobulle').remove();
}

addEvent(window,'load',launch);

function setPopinEvent(){
		$('.popin').each(function(){ 
			var wi = $(this).width();
			var hi = $(this).height();
			
			var hiWindow = $(document)[0].documentElement.clientHeight;
			var wiWindow = $(document).width();

			var top = (hiWindow/2)-(hi/2)+getScrollTop();
			if(top<0) top = 10;
			var left = (wiWindow/2)-(wi/2);
			$(this).attr('style','top:'+top+'px;left:'+left+'px;');
		});
		
		//btn close
		$('.close').unbind();
		$('.close').bind('click',function(){
			$(this).parent().parent().hide();
			return false;
		});	
}
function getPopin(id){
	setPopinEvent();
	$('.popin').hide();
	$("#"+id).show();
}
function getScrollTop(){
	if( document.body && ( document.body.scrollLeft || document.body.scrollTop ))
		return document.body.scrollTop;
	else
		return document.documentElement.scrollTop;
}

function dossier()
{
	$('#btnDossier').click( function() { 
				if($('#id_Dossier').val()==""){
					return false;
				}else{		
						window.location.href=$('#id_Dossier').val();
						return false;
					}
								     
			
	 } );
	 
}
function closePopup(){	
	$("#closePopin").click( function() { 								     
		window.close();	
	 } );
}
function openPopup(){	
	/* $(".OpenPopin").click( function() { 								     
		window.open('/nos-produits-vos-reductions/popUpOctobre.html', '', 'height=520, width=410, top=100, left=100, toolbar=no, menubar=no, location=no, resizable=yes, scrollbars=no, status=no'); 		return false;
	 } ); */
	 return false;
}
function initWidthOfNav(){
	var wi = $('.stdNavTabVideo').width();
	var nbrTab = $('.stdNavTabVideo li').length;
	var aSosutrire = 40 * nbrTab;
	wi -= aSosutrire;
	var myWi = Math.floor(wi/nbrTab);
	$('.stdNavTabVideo li span').width(myWi);
	
}
function showItem(){
	
	$(".productCarousel .jcarousel-item h1 a").unbind("click");
	$(".productCarousel .jcarousel-item h1 a").bind("click",function(){
		
		var index=$(".productCarousel .jcarousel-item").index($(this).parents('li'));
			
			$(".productCarousel .jcarousel-item").removeClass("active");
			$(this).parents('li').addClass("active");
			$(".contentPartner .items").hide();
			$(".contentPartner #item"+index).show();
			
			var h1 = $(this).parents('h1');
			var content1 = $(this).html();
			
			$('.productCarousel .jcarousel-item h1 > img').each(function(){
				var content = $(this).parents('h1').html();
				$(this).parents('h1').html("<a href='#' class='pdtBlock'>"+content+"</a>")
			})
					
		$(this).replaceWith(content1+'');
		showItem();
		return false;	
	});
	
}

function popUpShow(){
	$('.promoBlock .OpenPopin a').click(function(){
		 var haut = (screen.height-262)/2;
		var gauche = (screen.width-530)/2;
       window.open("/nos-produits-vos-reductions/pupUpKubor.html","TITRE","top="+haut+",left="+gauche+",width=530,height=262");
	   return false;
	})
}

/* initIntersticiel  */

function initIntersticiel(popinURL,objWidth, objHeight, objURL, objAlpha, objBgColor) {		
		openPopinLayer(popinURL, "interstitiel");
		$("#page").ajaxComplete(function(request, settings){								  
			var bodyHeightInter = (document.documentElement.clientHeight)/2;	
			var blockMargin = bodyHeightInter - objHeight/2;		
			var cssLayer = {
				backgroundColor: objBgColor,
				opacity: objAlpha
			}
			var cssBlock = {
				width: objWidth + "px",
				height: objHeight + "px",
				top: blockMargin
			}
			
			jQuery("#bgPopinLayer").css(cssLayer);
			$("#innerIntersticiel").css(cssBlock);
			
			if(jQuery("#innerIntersticiel").length > 0){
			    var flashvars = {};
			    var params = {
					wmode: "transparent"
				};
		        var attributes = {};
		        swfobject.embedSWF(objURL, "interstitielContainer", objWidth, objHeight, "8.0.0", "/App_Themes/Common/swf/expressInstall.swf", flashvars, params, attributes);
			}
			
			
			/* TIMER */
			//setTimeout(function(){ $("#popinLayerDisplay").remove() }, 120000);
		});
}
// Ouverture de Popin //
function openPopinLayer(urlPopin, newClass){
	$("#popinLayerDisplay").remove();
	$("#page").after('<div id="popinLayerDisplay"><div id="bgPopinLayer" class="'+newClass+'"></div></div>')
	$.ajax({
		type:"GET",
		url:urlPopin,
		success:function(msg) {
			//$('#bgPopinLayer').find('.loading').remove();
			$("#bgPopinLayer").after(msg);			
			closePopinLayer();
			backgroundPopin();
		}
	});
}

// Fermeture de popin //
function closePopinLayer(){
	$(".btClosePopinLayer").click(function() {
		$("#popinLayerDisplay").remove();
		if (typeof document.body.style.maxHeight === "undefined") { 
			$("select").show();
		}
		return false;
	});
}

// gestion taille background Popin //
function backgroundPopin(){
	var bodyHeight = $("body").height();
	$("#bgPopinLayer").height(bodyHeight);
	if (typeof document.body.style.maxHeight === "undefined") { // IE6
		var bodyWidth = $("body").width();
		$("#popinLayerDisplay").width(bodyWidth);
		$("#bgPopinLayer").width(bodyWidth);
		$("select").hide();
	}
}

//appelable via le flash
function closeIntermediateScreen(){
    $("#popinLayerDisplay").remove();
    if (typeof document.body.style.maxHeight === "undefined") { 
        $("select").show();
	}    
}

function createCookie(name, days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"=true"+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function ongletPapillotes(){
	if($('.discover_pdt .stdNavTab').length == 2)
	$($('.discover_pdt .stdNavTab')[1]).remove();
	
}

function popinPromoEvent(){
	if($('#displayPopin').length)
	$('.popinPromoLink').css({cursor:"pointer"});
	//__ overture de la popin __\\
	
	$('.popinPromoLink').click(function(){
		
		$('#displayPopin').show();
		if ($.browser.msie && navigator.appVersion.indexOf('MSIE 6') != -1)
		$('.searchPush .searchForm select').css({visibility:"hidden"});
		centerPopin();
		return false;
	});
	
	//__ fermeture  de la popin  __\\
	
	$('.popinPromo .closeP').click(function(){
		$('#displayPopin').hide();
		if ($.browser.msie && navigator.appVersion.indexOf('MSIE 6') != -1)
		$('.searchPush .searchForm select').css({visibility:"visible"});
		return false;
	});
	
	$(document).click(function(e){
	    if($('#displayPopin').is(':visible') && !$(e.target).parents('.popinPromo').length){
			$('#displayPopin').hide();
			if ($.browser.msie && navigator.appVersion.indexOf('MSIE 6') != -1)
			$('.searchPush .searchForm select').css({visibility:"visible"});
			return false;
	    }
	});
	
	//__ Centrage  de la popin  __
	
	$(window).bind('scroll',function(){
		centerPopin();
    })

}

function centerPopin(){
	var wi = $('.popinPromo').width();
	var hi = $('.popinPromo').height();
	
	var hiWindow = $('body').height();
	var wiWindow = $('#page').width();

	var top = (hiWindow/2)-(hi/2)+getScrollTop();
	if(top<0) top = 10;
	var left = (wiWindow/2)-(wi/2);
	$('.popinPromo').css({top:top-200+'px',left:left+'px'});
}

// Règlement Echantillons
function ShowReglement(){
	if($('#overlay').length) $('#overlay').remove();
	$('#page').after('<div id="overlay"></div>');
	$('#overlay').height($(document).height());
	$('#overlay').width($(window).width());
	//Set position
	SetPosition();
	$('#reglement_popin').show();
}
// Set position popin Echantillons
function SetPosition(){
	var popinLeft = ($(window).width() - $('#reglement_popin').width())/2;
	var popinTop = ($(window).height() - $('#reglement_popin').height())/2;
	if(popinLeft < 45){
		popinLeft = 0;
	}else if ($(window).width() < $('#reglement_popin').width()+270){
		popinLeft = popinLeft-20;
	}
	
	if (popinTop <0){
		popinTop = 0;
	}
	//console.log($(window).width() +' popinLeft '+popinLeft+' popinTop '+popinTop);
	$('#reglement_popin').css({
		left : popinLeft+'px',
		top : popinTop+'px'
	});
}
// resize Echantillons
$(window).resize(function(){
	$('#overlay').width($(window).width());
	SetPosition();
});




