var GEN_nbBlocs = 100;

$(document).ready(function() {



	$("#sendFormUserUpdate").click(function(){
		$.post('/dyn/cgi/create_update_user.php',$("#formUserCreate").serialize(), function(data) {
			$("#iFrameBR").css('visibility', 'visible');
			document.getElementById('iFrameBR').src = document.getElementById('iFrameBR').src;
		});
	 });


	$("#registerForm #PublishButton").click(function(){
		var axel = Math.random() + ""; 
		var a = axel * 10000000000000; 
		bscounter = new Image();
		bscounter.src = "http://fls.doubleclick.net/activityi;src=2943869;type=lesie135;cat=lesie594;ord=1;num=' + a + '?";
	 });



	$("body, html").mousedown(function (b) { 
		if(b.which == 2)
			return false
	});

	$("body, html").mousewheel(function(event, delta) {
		if(!popOn) {
			$("#bgCadre").hide();
			$("#scrollHelp").click();
		}
	});			

	prepareBlocs();

	$('#searchtext').keypress(function(evt) {
	  if(evt.keyCode == 13)
	  {
		$('#id_search_general').attr("href","/Recherche?SearchText=" + $('#searchtext').val()) ;
		$("#id_search_general").click();
	  }
	});
	
	
	
	$('#btPanneauBlue').click(function() {
		if($("#btPanneauBlue").attr("class") == "closeBlue")
		{
			stopExec = 0;
			$("#panneau").css("display", "block");
			$("#panneau").fadeTo(0,0,function() {
				$("#panneau").animate({top:"+=318px", opacity: 1},500);
				$("#btPanneauBlue").animate({top:"+=297px"},500,function(){
					$("#btPanneauBlue").attr("class", "openBlue");
				});
			});
		}
		else
		{
			stopExec = 1;
			$("#btPanneauBlue").animate({top:"-=297px"},500);
			$("#panneau").animate({top:"-=318px", opacity: 0},500,function() {
				$("#panneau").css("display", "none");
				$("#btPanneauBlue").attr("class", "closeBlue");
			});
		}
	
	});
	
	$('#btPanneau').click(function() {
		if($("#btPanneau").attr("class") == "close")
		{
			stopExec = 0;
			$("#panneau").css("display", "block");
			$("#panneau").fadeTo(0,0,function() {
				$("#panneau").animate({top:"+=318px", opacity: 1},500);
				$("#btPanneau").animate({top:"+=297px"},500,function(){
					$("#btPanneau").attr("class", "open");
				});
			});
		}
		else
		{
			stopExec = 1;
			$("#btPanneau").animate({top:"-=297px"},500);
			$("#panneau").animate({top:"-=318px", opacity: 0},500,function() {
				$("#panneau").css("display", "none");
				$("#btPanneau").attr("class", "close");
			});
		}
	
	});
	
	
	$('a#popValidBt').click(function() {
		$('.popValidAll').hide(0);
		$('#popValid_' + this.className).show('fast');
	});

	
	$("#pattern_search_simple").focus(function() {
		$.ajax({
		   url: '/layout/set/simple/content/view/recette_list',
		   success: function(data){
									var tab = data.split(',');
									$("#pattern_search_simple").autocomplete(tab, {
										width: 228,
										cacheLength: 50,
										matchContains: true,
										scroll: true,
										minChars: 2,
										scrollHeight: 200,
										selectFirst: false
									});
		   }
		});
	});
	
	
	$("#sliderBudg").slider({ 	animate: 'slow',
								step: 1,
								min: 0,
								max: 4,
								slide: function(event, ui) {
										if(ui.value == 0)
										{$(".budgetValeur").html("&nbsp;Tout me va")}
										else if(ui.value == 1)
										{$(".budgetValeur").html("&nbsp;Serr&eacute;")}
										else if (ui.value == 2)
										{$(".budgetValeur").html("&nbsp;Economique")}
										else if (ui.value == 3)
										{$(".budgetValeur").html("&nbsp;Moyen")}
										else if (ui.value == 4)
										{$(".budgetValeur").html("&nbsp;Elev&eacute;")}
									},
								stop:function(event, ui) {
															$("#valeurBudgetId").attr("value",ui.value)
														}
							});
	
	$("#sliderTmps").slider({ 	animate: 'slow',
								step: 1,
								min: 0,
								max: 7,
								slide: function(event, ui) {
										if(ui.value == 0)
										{$(".tempsValeur").html("&nbsp;Tout me va")}
										else if(ui.value == 1)
										{$(".tempsValeur").html("&nbsp;Moins de 10 minutes")}
										else if (ui.value == 2)
										{$(".tempsValeur").html("&nbsp;De 10 à 20 minutes")}
										else if (ui.value == 3)
										{$(".tempsValeur").html("&nbsp;De 20 à 30 minutes")}
										else if (ui.value == 4)
										{$(".tempsValeur").html("&nbsp;De 30 à 40 minutes")}
										else if (ui.value == 5)
										{$(".tempsValeur").html("&nbsp;De 40 à 50 minutes")}
										else if (ui.value == 6)
										{$(".tempsValeur").html("&nbsp;De 50 à 60 minutes")}
										else if (ui.value == 7)
										{$(".tempsValeur").html("&nbsp;Plus de 60 minutes")}
									},
								stop:function(event, ui) {
															$("#valeurTempsId").attr("value",ui.value)
														}
							});
	
	
////////// AUTRES ////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	
	
	$('#wallContainer').mouseleave(function(event) {
		$('.upRoll, .rightRoll, .downRoll, .masque').hide(100); 
	});
	
	$('#search_recipe_result').click(function(event) {
		if(($("#btPanneau").attr("class") == "open")&&(!stopExec))
		{
			$("#btPanneau").animate({top:"-=297px"},500);
			$("#panneau").animate({top:"-=318px", opacity: 0},500,function() {
				$("#panneau").css("display", "none");
				$("#btPanneau").attr("class", "close");
			});
		}
	});
	
	
	$('#search_recipe_result').click(function(event) {
		if(($("#btPanneauBlue").attr("class") == "openBlue")&&(!stopExec))
		{
			$("#btPanneauBlue").animate({top:"-=297px"},500);
			$("#panneau").animate({top:"-=318px", opacity: 0},500,function() {
				$("#panneau").css("display", "none");
				$("#btPanneauBlue").attr("class", "closeBlue");
			});
		}
	});
	
	
	
	$('body').keydown(function(event) {
		 if (!popOn)
		 {
			 if( event.keyCode == 39)
			 {
				$("a#moveRight.recipeRight").click();
				$("a#moveRight.universRight").click();
			 }
			 if( event.keyCode == 37)
			 {
				$("a#moveLeft.recipeLeft").click();
				$("a#moveLeft.universLeft").click();
			 }
		 }
	});

	$('body').mousewheel(function(event, delta) {
		if (!popOn)
		{
			if (delta < 0){
				$("a#moveRight.recipeRight").click();
				$("a#moveRight.universRight").click();
			}else if (delta > 0){
				$("a#moveLeft.recipeLeft").click();
				$("a#moveLeft.universLeft").click();
			}
		}
	});			

	$("input#searchtext").focus(function(){
		if($(this).attr("value") == "Je recherche"){
			
			$(this).attr("value","");
		}
	});
	
	$("input#searchtext").blur(function(){
		if($(this).attr("value") == ""){
			$(this).attr("value","Je recherche");
		}
	});		
	
	
	$("input#pattern_search_simple").focus(function(){
		if($(this).attr("value") == "Je recherche"){
			
			$(this).attr("value","");
		}
	});
	
	$("input#pattern_search_simple").blur(function(){
		if($(this).attr("value") == ""){
			$(this).attr("value","Je recherche");
		}
	});
	
	if (document.getElementById('icon'))
	{
		$.ajax({
		   type: "GET",
		   url: "/dyn/cgi/meteo.php",
		   data: "action=city",
		   success: function(msg){
			   $("#city").text(msg);
		   }
		 });
		
		$.ajax({
		   type: "GET",
		   url: "/dyn/cgi/meteo.php",
		   data: "action=low",
		   success: function(msg){
			   $("#tmp_low").text(msg);
		   }
		 });
		
		$.ajax({
		   type: "GET",
		   url: "/dyn/cgi/meteo.php",
		   data: "action=high",
		   success: function(msg){
			   $("#tmp_high").text(msg);
		   }
		 });
		
		$.ajax({
		   type: "GET",
		   url: "/dyn/cgi/meteo.php",
		   data: "action=icon",
		   success: function(msg){
			   document.getElementById('icon').src = msg;
			   //$('#infoWeather').fadeIn("slow");
		   }
		 });
	}
	
	$("a.envie_de").click(function(){
		$("#recetteName").animate({marginLeft: "+=50px",opacity: 0},400);		
		$("#recetteImage").fadeOut("fast");
		$.ajax({
		   url: "/layout/set/simple/content/view/rand_envie_de",
		   success: function(msg){
			   $("#recetteName").html(msg);
			   $("#recetteName").animate({marginLeft: "5px", opacity: 1},400);
			   $("#recetteName").fadeIn("fast");
			   $('.nyroModal').nyroModal();
		   }
		});
	});


	$("a.citation").click(function(){
		$("#humeurDay").animate({marginLeft: "+=50px",opacity: 0},400);		
		$("#humeurDay").fadeOut("fast");
		$.ajax({
		   url: "/layout/set/simple/content/view/rand_phrase_du_jour",
		   success: function(msg){
			   $("#humeurDay").html(msg);
			   $("#humeurDay").animate({marginLeft: "5px", opacity: 1},400);
			   $("#humeurDay").fadeIn("fast");
		   }
		});
	});




});


function getBlockOffset(nbr, id)
{
	if (id == 'tmp_ne')
	{			
		SetRecipeCarrousselByOffset(id,nbr);							
	}
	else
	{
		SetRecipeCarrousselByOffset(id,nbr-1);
	}						
}


var timeSlide = 5000;
var timeTransition = 500;
function startSlide(id, nbr, idCurrent)
{
	////console.log(id + ", " + nbr + ", "+ idCurrent);

	if (idCurrent-1 < 0)
	{idPrev = nbr;}
	else
	{idPrev = idCurrent-1;}
	
	$("#" + id + "_" + idPrev).fadeTo(timeTransition, 0);
	$("#" + id + "_" + idCurrent).fadeTo(timeTransition, 1);
	
	idCurrent = idCurrent + 1;
	
	if (idCurrent > nbr)
		idCurrent = 0;
	
	eval("idVar"	+ id + "= id;");
	eval("nbrVar"	+ id + "= nbr;");
	eval("idCurrentVar"	+ id + "= idCurrent;");
	
	setTimeout("startSlide(idVar"+id + ", nbrVar"+id + ", idCurrentVar"+id + ");" , timeSlide);
}




var timeSlideBloc = 7500;
function startSlideBloc()
{
	$(".mainImage .rightContent").click();
	setTimeout("startSlideBloc();" , timeSlideBloc);
}





function cleanFormFilterRecipe()
{	
		if (document.form_filter_recipe.mode_display)
		{
			document.form_filter_recipe.mode_display.value = 1;	
		}
		
		if (document.form_filter_recipe.offset)
		{
			document.form_filter_recipe.offset.value = 0;	
		}
		/*
		if (document.form_filter_recipe.preparation_time_cat)
		{
			document.form_filter_recipe.preparation_time_cat.value = "";	
		}
		if (document.form_filter_recipe.cost)
		{
			document.form_filter_recipe.cost.value = "";	
		}
		if (document.form_filter_recipe.component_0)
		{
			document.form_filter_recipe.component_0.value = "";	
		}
		if (document.form_filter_recipe.component_1)
		{
			document.form_filter_recipe.component_1.value = "";	
		}
		if (document.form_filter_recipe.component_2)
		{
			document.form_filter_recipe.component_2.value = "";	
		}
		if (document.form_filter_recipe.component_3)
		{
			document.form_filter_recipe.component_3.value = "";	
		}
		if (document.form_filter_recipe.component_4)
		{
			document.form_filter_recipe.component_4.value = "";	
		}
		if (document.form_filter_recipe.component_5)
		{
			document.form_filter_recipe.component_5.value = "";	
		}
		if (document.form_filter_recipe.component_6)
		{
			document.form_filter_recipe.component_6.value = "";	
		}
		if (document.form_filter_recipe.component_7)
		{
			document.form_filter_recipe.component_7.value = "";	
		}
		*/

}


function refreshResultRecipe()
{	
	cleanFormFilterRecipe();
	document.form_filter_recipe.submit();
}


function refreshResultRecipeAjax()
{	
	cleanFormFilterRecipe();		
	$.post('/_Travail/Resultat-recherche-recette',$("#filter_recipe").serialize(), function(data) {
		$('#search_recipe_result').html(data);
		prepareBlocs();
	});
		  		  	
}

var maxRight = 0;
var slideUnivers = 1;
function passMaxRight(n)
{
	maxRight = n;
	if (n == 1 || n == 0)
		$("a#moveRight.universRight").hide('fast');
}

var popOn = 0;
var vAnim = 400;
var currentOffset = 2;
var retReq = 0;
var busyMoveRight = 0;
var busyMoveLeft = 0;
var busySlideRight = 0;
var busySlideLeft = 0;
//var resTemp = null;
var SetRecipeCarrousselByOffsetBusy = 0;
var videoVar = 0;
var resRTemp = null;
var resLTemp = null;
var interVar = 0;
var stopExec = 0;
var nodeId;



function etatPop(val)
{
	popOn = val;
}

function setNode(val)
{
	nodeId = val;
}

function setVideoVar(flag)
{
	videoVar = flag;
}

function setInterVar(flag)
{
	interVar = flag;
}

function prepareBlocs()
{
	
	////////// AFFICHAGE DES BLOCS (EFFET FONDU) ///////////////////////////////////////////////////////////////////////////////////
	
	// Blocs univers
	if(document.getElementById('bloc_1'))
	{
//alert("in");		
		for (i=1;i<GEN_nbBlocs;i++)
		{
			if(document.getElementById('bloc_' + i))
			{
				if ((navigator.userAgent.search("MSIE 7") == -1)&&(navigator.userAgent.search("MSIE 8") == -1))
				{
					$('#bloc_' + i).fadeTo( Math.floor(Math.random()*1150)+250, 1);
				}
				else
				{
					document.getElementById('bloc_' + i).style.display = "block";
				}
			}
		}
	}
	else
	{
		// Blocs Home
		var list_blocs = $('#universBlocs').find('.bloc');
		for (var i = 0; i < list_blocs.length; i++) 
		{
			if ((navigator.userAgent.search("MSIE 7") == -1)&&(navigator.userAgent.search("MSIE 8") == -1))
			{
				$('#' + list_blocs[i].id).fadeTo( Math.floor(Math.random()*1150)+250, 1);
			}
			else
			{
				document.getElementById(list_blocs[i].id).style.display = "block";
			}
		}	
	
	}
	
	////////// HOME DRAG & DROP ////////////////////////////////////////////////////////////////////////////////////////////////////
	// CONFIG
	
	
	var coefBg	= 1.5;
	var pX		= 0;
	var pY		= 0;
	var bloc = $(".bloc").offset();
	var id = null;
	var idClick = 0;
	
	$("#zoneDrag").draggable({
								//revert: true,
								containment: [-1250, -1800, 2250, -750],
								scroll: false,
								start: function(event, ui) {
															if (idClick)
															{
																id = document.getElementById(idClick).id;
																document.getElementById(idClick).id = "off" + id;
															}
															$('#header').dequeue();
															if ((navigator.userAgent.search("MSIE 7") == -1)&&(navigator.userAgent.search("MSIE 8") == -1))
															{
																$('#header').fadeTo( 400,0.20);
															}
															$('#popValid_2').hide('fast');
															$("#zoneDrag, #zoneDrag a, .blocHtml").css("cursor", "url(/design/fre/images/handClose.cur),auto");
								},
								drag: function(event, ui){
															pX = (bloc.left - 640)/coefBg;
															pY = (bloc.top - 440)/coefBg;
															bloc = $(".bloc").offset();
															$(".homePage").css("backgroundPosition", parseInt(pX+114) + "px " + parseInt(pY-129) + "px"); 
								},
								stop: function(event, ui) {
															
															$("#zoneDrag, .blocHtml").css("cursor", "url(/design/fre/images/handOpen.cur),auto");
															$("#zoneDrag a").css("cursor", "pointer");
															if ((navigator.userAgent.search("MSIE 7") == -1)&&(navigator.userAgent.search("MSIE 8") == -1))
															{
																$('#header').fadeTo( 600,1);
															}
															
															
															idClick = 0;
																														
															if(!document.getElementById('bloc_1'))
															{
																// Blocs Home
																var list_blocs = $('#universBlocs').find('div');
																var RegularExpression = /bloc_(\d+)/;	
																for (var i = 0; i < list_blocs.length; i++) 
																{
																	ret = list_blocs[i].id.search(RegularExpression);
																	if (ret != -1)
																	{
																		if(!document.getElementById(list_blocs[i].id))
																			break;	
																		
																		x = document.getElementById(list_blocs[i].id).offsetLeft+(bloc.left-517);
																		y = document.getElementById(list_blocs[i].id).offsetTop+(bloc.top-620);
																		if(x >= -700 && x <= 400 && y <= -170)
																		{
																			if (navigator.userAgent.search("MSIE 7") == -1)
																			{
																				$('#' + list_blocs[i].id).fadeTo(1000,0.25);
																			}
																		}
																		else
																		{
																			if (navigator.userAgent.search("MSIE 7") == -1)
																			{
																				$('#' + list_blocs[i].id).fadeTo(500,1);
																			}
																		}
																	}
																}	
															}
															
								}
	});	
	
	$(".bloc" ).draggable({scroll: false});
	$(".bloc" ).draggable( "disable");
	
	
	$("#zoneDrag a").mousedown(function(e) {
										
										idClick = this.id;
						 });
	
	
	////////// UNIVERS ////////////////////////////////////////////////////////////////////////////////////////////////////////

	
	if (document.getElementById("countRecipe"))
		var countRecipe = parseInt(document.getElementById("countRecipe").innerHTML)-1;
	
	
	$("a#moveLeft.universLeft").click(function(){
		if ((slideUnivers > 1)||(interVar))
		{
			$("#universBlocs").animate({left: "+=900px"});
			$("#univers").animate({backgroundPosition: "-=210px 0px"}); 
			slideUnivers = slideUnivers - 1;
			if (slideUnivers == 1)
				$("a#moveLeft.universLeft").hide('fast');
			$("a#moveRight.universRight").show('fast');
			//console.log("page : " + slideUnivers);
		}
	});

	$("a#moveRight.universRight").click(function(){
		if ((slideUnivers < maxRight)||(interVar))
		{
			$("#universBlocs").animate({left: "-=900px"});
			$("#univers").animate({backgroundPosition: "+=210px  0px"}); 
			slideUnivers =  slideUnivers + 1;
			if (slideUnivers == maxRight)
				$("a#moveRight.universRight").hide('fast');
			$("a#moveLeft.universLeft").show('fast');
			////console.log("page : " + slideUnivers);
		}
	});



	$("a#moveRight.recipeRight").click(function(event){
		
		if((busyMoveRight == 0)&&(busyMoveLeft == 0)&&(SetRecipeCarrousselByOffsetBusy == 0))
		{
			busyMoveRight = 1;
			
			
			
			currentOffset = parseInt(document.getElementById("idItem").innerHTML)+1;
			
			if (currentOffset == countRecipe+1)
				currentOffset = 0;

			$("#idItem").html(currentOffset);
			
			
			if ((currentOffset >= countRecipe-2)&&(currentOffset <= countRecipe))
			{
				
				if(videoVar)
				{
					SetVideoCarrousselByOffset('tmp_ne',(countRecipe-currentOffset)-2, nodeId);
					SetVideoCarrousselByOffset('tmp_ba',currentOffset-3, nodeId);
				}
				else
				{
					SetRecipeCarrousselByOffset('tmp_ne',(countRecipe-currentOffset)-2);
					SetRecipeCarrousselByOffset('tmp_ba',currentOffset-3);
				}
			}
			else
			{
				if(videoVar)
				{
					SetVideoCarrousselByOffset('tmp_ne',currentOffset+3, nodeId);
				}
				else
				{
					SetRecipeCarrousselByOffset('tmp_ne',currentOffset+3);
				}
				
				if ((currentOffset <= 2)&&(currentOffset >= 0))
				{
					if(videoVar)
					{
						SetVideoCarrousselByOffset('tmp_ba',countRecipe-(2-currentOffset), nodeId);
					}
					else
					{
						SetRecipeCarrousselByOffset('tmp_ba',countRecipe-(2-currentOffset));
					}
				}
				else
				{
					if(videoVar)
					{
						SetVideoCarrousselByOffset('tmp_ba',currentOffset-3, nodeId);
					}
					else
					{
						SetRecipeCarrousselByOffset('tmp_ba',currentOffset-3);
					}
				}
			}
			
			
			
			$("#univers").animate({backgroundPosition: "+=210px 0px"},vAnim);
			
			
			if ((navigator.userAgent.search("MSIE 7") == -1)&&(navigator.userAgent.search("MSIE 8") == -1))
			{
				$("#bloc_0").not('.playButton').animate({opacity: 0},0);
			}
			else
			{
				$("#bloc_0").not('.playButton').animate({},0);
			}
			$("#bloc_0").html(resRTemp);
			
			$("#bloc_1").not('.playButton').animate({left: "-=200px", opacity: 0},vAnim);
			
			$("#bloc_2").not('.playButton').animate({left: "-=200px", top:"-=10px"},vAnim);
			$("#bloc_2").css('z-index', 1);
			$("#bloc_2 img").not('.playButton').animate({height: "-=25px"},vAnim);
		
			$("#bloc_3").not('.playButton').animate({left: "-=200px", top:"-=10px"},vAnim);
			$("#bloc_3").css('z-index', 2);
			$("#bloc_3 img").not('.playButton').animate({height: "-=25px"},vAnim);
			
			$("#bloc_4").not('.playButton').animate({left: "-=200px", top:"+=10px"},vAnim);
			$("#bloc_4").css('z-index', 3);
			$("#bloc_4 img").not('.playButton').animate({height: "+=25px"},vAnim);
			
			$("#bloc_5").not('.playButton').animate({left: "-=200px", top:"+=10px"},vAnim);
			$("#bloc_5").css('z-index', 2);
			$("#bloc_5 img").not('.playButton').animate({height: "+=25px"},vAnim, function() {
				$('#bloc_1').remove();
			});
		
			$("#bloc_0").css('z-index', 1);
			
			if ((navigator.userAgent.search("MSIE 7") == -1)&&(navigator.userAgent.search("MSIE 8") == -1))
			{
				$("#bloc_0").not('.playButton').animate({left: "-=200px", opacity: 1},vAnim, function() {
					$('#bloc_2').attr('id', "bloc_1");
					$('#bloc_3').attr('id', "bloc_2");
					$('#bloc_4').attr('id', "bloc_3");
					$('#bloc_5').attr('id', "bloc_4");
	
					$('#bloc_0').attr('id', "bloc_5");
					$('#bloc_5').after('<div id="bloc_0" style="position:relative; top:350px; left:1000px;"></div>');
					busyMoveRight = 0;
					$('.nyroModal').nyroModal();
				});
			}
			else
			{
				$("#bloc_0").not('.playButton').animate({left: "-=200px"},vAnim, function() {
					$('#bloc_2').attr('id', "bloc_1");
					$('#bloc_3').attr('id', "bloc_2");
					$('#bloc_4').attr('id', "bloc_3");
					$('#bloc_5').attr('id', "bloc_4");
	
					$('#bloc_0').attr('id', "bloc_5");
					$('#bloc_5').after('<div id="bloc_0" style="position:relative; top:350px; left:1000px;"></div>');
					busyMoveRight = 0;
					$('.nyroModal').nyroModal();
				});
			}

		}
	
	});

	$("a#moveLeft.recipeLeft").click(function(event){
		
		if((busyMoveLeft == 0)&&(busyMoveRight == 0)&&(SetRecipeCarrousselByOffsetBusy == 0))
		{
			
			busyMoveLeft = 1;
			
			currentOffset = parseInt(document.getElementById("idItem").innerHTML-1);

			if (currentOffset == -1)
				currentOffset = countRecipe;
				
			//console.log("currentOffset : " + currentOffset);
			$("#idItem").html(currentOffset);
			
			if ((currentOffset <= 2)&&(currentOffset >= 0))
			{
				
				
				if(videoVar)
				{
					SetVideoCarrousselByOffset('tmp_ba',countRecipe-(2-currentOffset), nodeId);
					SetVideoCarrousselByOffset('tmp_ne',currentOffset+3, nodeId);
				}
				else
				{
					SetRecipeCarrousselByOffset('tmp_ba',countRecipe-(2-currentOffset));
					SetRecipeCarrousselByOffset('tmp_ne',currentOffset+3);
				}
			}
			else
			{
				if(videoVar)
				{
					SetVideoCarrousselByOffset('tmp_ba',currentOffset-3, nodeId);
				}
				else
				{
					SetRecipeCarrousselByOffset('tmp_ba',currentOffset-3);
				}
				
				if ((currentOffset <= countRecipe)&&(currentOffset >= countRecipe-2))
				{
					if(videoVar)
					{
						SetVideoCarrousselByOffset('tmp_ne',(countRecipe-currentOffset)-2, nodeId);
					}
					else
					{
						SetRecipeCarrousselByOffset('tmp_ne',(countRecipe-currentOffset)-2);
					}
				}
				else
				{
					if(videoVar)
					{
						SetVideoCarrousselByOffset('tmp_ne',currentOffset+3, nodeId);
					}
					else
					{
						SetRecipeCarrousselByOffset('tmp_ne',currentOffset+3);
					}
				}
			}
			
			$("#univers").not('.playButton').animate({backgroundPosition: "-=210px 0px"},vAnim); 
			
			$("#bloc_6").not('.playButton').animate({},0);
			$("#bloc_6").html(resLTemp);
			
			$("#bloc_5").not('.playButton').animate({left: "+=200px", opacity: 0},vAnim);
			
			$("#bloc_4").not('.playButton').animate({left: "+=200px", top:"-=10px"},vAnim);
			$("#bloc_4").css('z-index', 1);
			$("#bloc_4 img").animate({height: "-=25px"},vAnim);
			
			$("#bloc_3").not('.playButton').animate({left: "+=200px", top:"-=10px"},vAnim);
			$("#bloc_3").css('z-index', 2);
			$("#bloc_3 img").not('.playButton').animate({height: "-=25px"},vAnim);
			
			$("#bloc_2").not('.playButton').animate({left: "+=200px", top:"+=10px"},vAnim);
			$("#bloc_2").css('z-index', 3);
			$("#bloc_2 img").not('.playButton').animate({height: "+=25px"},vAnim);
			
			$("#bloc_1").not('.playButton').animate({left: "+=200px", top:"+=10px"},vAnim);
			$("#bloc_1").css('z-index', 2);
			$("#bloc_1 img").not('.playButton').animate({height: "+=25px"},vAnim, function() {
				$('#bloc_5').remove();
			});
			
			$("#bloc_6").css('z-index', 1);
			
			if ((navigator.userAgent.search("MSIE 7") == -1)&&(navigator.userAgent.search("MSIE 8") == -1))
			{
				$("#bloc_6").not('.playButton').animate({left: "+=200px", opacity: 1},vAnim, function() {
					
					$('#bloc_4').attr('id', "bloc_5");
					$('#bloc_3').attr('id', "bloc_4");
					$('#bloc_2').attr('id', "bloc_3");
					$('#bloc_1').attr('id', "bloc_2");
					
					$('#bloc_6').attr('id', "bloc_1");
					$('#bloc_1').before('<div id="bloc_6" style="position:relative; top:350px; left:-200px;"></div>');
					busyMoveLeft = 0;
					$('.nyroModal').nyroModal();
				});
			}
			else
			{
				$("#bloc_6").not('.playButton').animate({left: "+=200px"},vAnim, function() {
					
					$('#bloc_4').attr('id', "bloc_5");
					$('#bloc_3').attr('id', "bloc_4");
					$('#bloc_2').attr('id', "bloc_3");
					$('#bloc_1').attr('id', "bloc_2");
					
					$('#bloc_6').attr('id', "bloc_1");
					$('#bloc_1').before('<div id="bloc_6" style="position:relative; top:350px; left:-200px;"></div>');
					busyMoveLeft = 0;
					$('.nyroModal').nyroModal();
				});
			}

}
	
	});
	
	
	
}


function votePoll(formId,divId)
{
	$.post('/content/action',$("#" + formId).serialize(), function(data) 
																	{		   		  
																		//alert(data);																 
																 		$('#' + divId).html(data);														
																    });
}


function refreshBlocFromUrl(url,divId)
{
	$.ajax({
		   url: url,
		   success: function(data){
									 //alert(data);	
									 $('#' + divId).html(data);
		  						  }
		  });
	
}


function playQuiz(url_alias,formId,divId)
{
	var selected_answer;
    selected_answer = jQuery('#' + formId + ' input:radio:checked').val();
//alert(the_value);
	
	if (selected_answer)
	{	
		var url = '/' + url_alias + '/(answer)/' + selected_answer;
		$.ajax({
			   url: url,
			   success: function(data){
										 //alert(data);	
										 $('#' + divId).html(data);
									  }
			  });
	}
	else
	{
		alert("Vous devez selectionner une reponse !");	
	}
	
	
}


function var_dump(obj) 
{
   if(typeof obj == "object") {
      return "Type: "+typeof(obj)+((obj.constructor) ? "\nConstructor: "+obj.constructor : "")+"\nValue: " + obj;
   } else {
      return "Type: "+typeof(obj)+"\nValue: "+obj;
   }
}//end functio


function selectComponent(id)
{
	$('#componentsId').attr("value",id);
	for (var i=0;i<15;i++)
	{
//alert(i);			
		if ($('#div_component_' + i))
		{
//alert("in");				
			$('#div_component_' + i).attr("class","disabled");				
		}
	}
//alert(id);
	$('#div_component_' + id).attr("class","enabled"); 
}

function selectComponentOld(id)
{
	//alert($('#id_value_component_' + id).attr("value"));
			
	var selected = $('#id_value_component_' + id).attr("value");
	if (selected == 0)
	{
		$('#id_value_component_' + id).attr("value",1);
		$('#div_component_' + id).attr("class","enabled");
		
		
	}
	else
	{
		$('#id_value_component_' + id).attr("value",0);
		$('#div_component_' + id).attr("class","disabled");
	}	
}


function SetRecipeCarrousselByOffset(div_id,offSet)
{
	
	SetRecipeCarrousselByOffsetBusy = 1;
	
	if (document.form_filter_recipe.mode_display)
	{
		document.form_filter_recipe.mode_display.value = 2;	
	}

	document.form_filter_recipe.offset.value = offSet;	
	$.post('/_Travail/Resultat-recherche-recette',$("#filter_recipe").serialize(), function(data) {		  
		SetRecipeCarrousselByOffsetBusy = 0;
		if (div_id == 'tmp_ne')
			resRTemp =  data;
		if (div_id == 'tmp_ba')
			resLTemp =  data;
		});
}


function SetVideoCarrousselByOffset(div_id,offSet)
{
	SetRecipeCarrousselByOffsetBusy = 1;
	$.ajax({
	   type: "GET",
	   url: "/layout/set/popin/content/view/bloc_video/(node_id)/"+ nodeId +"/(offset)/" + offSet,
	   success: function(data){
			SetRecipeCarrousselByOffsetBusy = 0;
			if (div_id == 'tmp_ne')
				resRTemp =  data;
			if (div_id == 'tmp_ba')
				resLTemp =  data;
	   						}
	 });
	
}

function tLeft(){
	$("a#moveLeft.recipeLeft").click();
	t = setTimeout("tLeft();", 1);
}

function tRight(){
	$("a#moveRight.recipeRight").click();
	t = setTimeout("tRight();", 1);
}


function subscribeNewletter(id_form,id_div)
{				  
	var goodInput = 1;
	var msgError = "";
	
	var email =  $('#id_email_newsletter').attr('value'); 
	if (!isGoodEmail(email))
	{
		goodInput = 0;
		msgError += "Vous devez saisir votre email correctement !\n";
	}
	
	if (goodInput == 1)
	{		
		var axel = Math.random() + ""; 
		var a = axel * 10000000000000; 
		bscounter = new Image();
		bscounter.src = "http://fls.doubleclick.net/activityi;src=2943869;type=lesie135;cat=lesie863;ord=1;num=' + a + '?";

		$.post('/dyn/cgi/inscription_newsletter.php',$('#' + id_form).serialize(), function(data) {
								
				var ret = "Votre inscription a bien été prise en compte. Nous vous remercions de votre confiance. Vous recevrez prochainement la newsletter Lesieur.";
				$('#' + id_div).html(ret);
			   });
	}
	else
	{
		alert(msgError);
	}

}


function isGoodEmail(email)
{
	var reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');

	if(reg.test(email))
	{
		return(true);
	}
	else
	{
		return(false);
	}
}

function CleanNavHistory()
{
	//alert("CleanNavHistory");	
	$.ajax({
		   type: "GET",
		   url: "/_Travail/Clean-navigation-history",
		   data: "",
		   success: function(data){
			   //alert(data);
		   }
	});	
}



function showFormComment()
{
	
	$.post('/content/action',$("#id_form_post_comment").serialize(), function(data) 
																	{		   		  
																		$('#id_post_comment').html(data);
																		$('#id_post_comment').toggle(100);
																	});
	
}

function changeSearchUrl()
{
	//alert("inn");
	$('#id_search_general').attr("href","/Recherche?SearchText=" + $('#searchtext').val()) ;
	//alert($('#id_search_general').attr("href"));
}


function initCurHome()
{
	//init. curseur Home
	document.onselectstart = function(){ return false; }
	$("#zoneDrag, .blocHtml").css("cursor", "url(/design/fre/images/handOpen.cur),auto");
	$("#zoneDrag a").css("cursor", "pointer");
}



function colorBgChange(val)
{
	createCookie("bgColor", val, 2000);
	window.location.href= '/Mon-espace-personnel'; 
}


function createCookie(name,value,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+"="+value+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;
}

