tarteaucitron.init({
    //"hashtag": "#tarteaucitron", /* Ouverture automatique du panel avec le hashtag */
    "highPrivacy": false, /* désactiver le consentement implicite (en naviguant) ? */
    "orientation": "top", /* le bandeau doit être en haut (top) ou en bas (bottom) ? */
    "adblocker": false, /* Afficher un message si un adblocker est détecté */
    "showAlertSmall": false, /* afficher le petit bandeau en bas à droite ? */
    "cookieslist": false, /* Afficher la liste des cookies installés ? */
    "removeCredit": false, /* supprimer le lien vers la source ? */
    "handleBrowserDNTRequest": false, /* Deny everything if DNT is on */
    //"cookieDomain": ".domaine.tld" /* Nom de domaine sur lequel sera posé le cookie pour les sous-domaines */
});

var count = 0;

var x = 0;
var y = 0;

var isMobile={Android:function(){return navigator.userAgent.match(/Android/i)},BlackBerry:function(){return navigator.userAgent.match(/BlackBerry/i)},iOS:function(){return navigator.userAgent.match(/iPhone|iPad|iPod/i)},Opera:function(){return navigator.userAgent.match(/Opera Mini/i)},Windows:function(){return navigator.userAgent.match(/IEMobile/i)},any:function(){return isMobile.Android()||isMobile.BlackBerry()||isMobile.iOS()||isMobile.Opera()||isMobile.Windows()}};

$(document).ready(function()
{
  	AOS.init();

	// Parallax
	$('.parallax').CJparallax("center", -0.1, 0.1, true);
	
	$('a.scroll_slide-link').click(function(e){
		e.preventDefault();
		$id = $(this).attr('href');
		$('body,html').animate({
			scrollTop: $($id).offset().top -20
		}, 750);
	});

	// SLICK

	$("#slide_avis").slick({
		slidesToShow: 3,
		swipeToSlide: true,
		arrows: true,
		infinite: false,
		responsive: [
		  {
			breakpoint: 860,
			settings: {
			  arrows: false,
			  centerMode: false,
			  centerPadding: "40px",
			  slidesToShow: 1.2,
			},
		  },
		],
	  });

	  $(".slick-slider-contenu").slick({
		slidesToShow: 3,
		swipeToSlide: true,
		arrows: true,
		infinite: false,
		centerMode: true,
		initialSlide: 1,
		responsive: [
		  {
			breakpoint: 860,
			settings: {
			  arrows: false,
			  centerMode: false,
			  centerPadding: "40px",
			  slidesToShow: 1,
			},
		  },
		],
	  });

	  $("#galerie-partenaires").slick({
		slidesToShow: 3,
		swipeToSlide: true,
		arrows: true,
		infinite: true,
		autoplay: true,
    	autoplaySpeed: 1000,
		responsive: [
		{
			breakpoint: 1200,
			settings: {
				arrows: false,
				centerMode: false,
				centerPadding: "40px",
				slidesToShow: 3.1,
			},
			},
		  {
			breakpoint: 860,
			settings: {
			  arrows: false,
			  centerMode: false,
			  centerPadding: "40px",
			  slidesToShow: 2.1,
			},
		  },
		  {
			breakpoint: 430,
			settings: {
			  arrows: false,
			  centerMode: false,
			  centerPadding: "40px",
			  slidesToShow: 1.1,
			},
		  },
		],
	  });

	$(document).on("mouseover", ".note > i", function()
	{
		$(this).addClass("fas").removeClass("far");
		$(this).prevAll("i").addClass("fas").removeClass("far");
		$(this).nextAll("i").addClass("far").removeClass("fas");
	});
	$(document).on("click", ".note > i", function()
	{
		$(this).addClass("fas").removeClass("far");
		$(this).prevAll("i").addClass("fas").removeClass("far");
		$(this).nextAll("i").addClass("far").removeClass("fas");
		$(this).prevAll("input").val($(this).parent().children("i.fas").length);
	});
	$(document).on("mouseleave", ".note", function()
	{
		var note = $(this).children("input").val()
		$(this).children("i").each(function(index)
		{
			$(this).removeClass("fas").addClass("far");

			if(index+1 <= note) $(this).removeClass("far").addClass("fas");
		});
	});

	// DEFILEMENT
	document.querySelectorAll('a[href^="#"]').forEach(anchor => {
		anchor.addEventListener('click', function(e) {
			e.preventDefault();
	
			const targetId = this.getAttribute('href').substring(1);
			const targetElement = document.getElementById(targetId);
	
			if (targetElement) {
				window.scrollTo({
					behavior: 'smooth',
					top: targetElement.offsetTop,
				});
			}
		});
	});
	
	// CAPTCHA ----------------------------
	$("#captchagc > img:nth-of-type(1)").draggable({ revert: true, containment: "parent" });
	$("#captchagc > img + div").droppable({ 
		accept: "#captchagc > img:nth-of-type(1)", 
		activeClass: "accept", 
		hoverClass: "hover", 
		drop: function(event, ui)
		{
			$("#captchagc").addClass("valid");
			$.getJSON("ajax/form.php", function(data){
				if(data.result == 1)
				{
					var result = true;
					$("#captchagc").closest("form").find("input:required,select:required,textarea:required").each(function()
					{							
						if($(this).val().trim() == "")
						{
							$(this).css("border","1px solid #FF0000");
							$(this).on("click.captcha", function()
							{
								$(this).css("border", "");
								$(this).off("click.captcha");
							});
							result = false;
						}
					}).promise().done(function()
					{
						if(result)
						{
							$("#captchagc").append("<i class='fas fa-spinner-third fa-spin'></i>");
							$("#form_contact").submit();
						}
						else
						{
							$($("#captchagc > i").get(2)).remove();
							$("#captchagc").removeClass("valid");
						}
					});
					
				}
			});
		}
	});
	//----------------------------

	$(".acordeon > li > div:first-child").on("click", function()
	{
		if($(this).parent().hasClass("select")) $(this).parent().removeClass("select");
		else $(this).parent().addClass("select").siblings().removeClass("select");
	});

	$(window).on("hashchange",function()
	{
		setTimeout(function()
		{
			if(location.hash != "" && location.hash != "#_=_" && $("#page-"+(location.hash.substring(1))).length > 0) $("html,body").animate({ "scrollTop":$("#page-"+(location.hash.substring(1))).offset().top-($(window).width() <= 860 ? 0 : $("#header").height()) }, 1000);
			if(location.hash == "#bienvenue") $("html,body").animate({ "scrollTop":0 });
		},1000);
	});
	$(window).trigger("hashchange");


	var tableau = new Array(),
		windowH = $(window).height()*0.75,
		scroll = $(document).scrollTop();

	for(var i = 0; i < $(".fade-c, .fade").length; i++) 
	{
		tableau.push($($(".fade-c, .fade").get(i)));
		if (windowH + scroll > $($(".fade-c, .fade").get(i)).offset().top) 
		{
			$($(".fade-c, .fade").get(i)).addClass("visible");
		}
	}

	$(document).on("scroll", function()
	{
		var scroll = $(document).scrollTop();

		for(var i = 0; i < tableau.length; i++) 
		{
			if(windowH + scroll > $(tableau[i]).offset().top) 
			{
				$(tableau[i]).addClass("visible");
			}
		}

		if(scroll > 120 && !$('#header').hasClass("scroll")) 
		{
			$('#header').addClass("scroll");
		}
		else if(scroll < 120 && $('#header').hasClass("scroll"))
		{
			$('#header').removeClass("scroll");

		}
	});


	$(".bloc-accueil > li > a").on("mousemove", function(event)
	{
		if($(this).hasClass("anim")) 
		{
			$(this).removeClass("anim");
		}

		x = event.pageX - $(this).offset().left;
		y = event.pageY - $(this).offset().top;
		
		var perspectiveX = 8,
			perspectiveY = 8;

		var largeur = $(this).innerWidth(),
			hauteur = $(this).innerHeight();

		var top = $(this).position().top,
			left = $(this).position().left,
			bottom = top +  hauteur,
			right = left + largeur;	

		var pourcentX = ((x / largeur * 100)/100)-0.5,
			pourcentY = ((y / hauteur * 100)/100)-0.5;

		var resultX = pourcentX * (perspectiveX * 2),
			resultY = -(pourcentY * perspectiveY * 2);

		$(this).css("transform", "rotateY("+(resultX)+"deg) rotateX("+(resultY)+"deg)");
		$(this).css("box-shadow", -resultX+"px "+resultY+"px 25px rgba(107, 107, 107, 0.48)");

		var departY = hauteur/2,
			departX = largeur/2;

	});
	$(".bloc-accueil > li").on("mouseleave", function(){
		$(this).children("a").addClass("anim");
	});

	$.datepicker.setDefaults($.datepicker.regional["fr"]);
	$(".datepicker").each(function()
	{
		$(this).datepicker({
			altField: $(this).next(),
			altFormat: "yy-mm-dd",
			dateFormat:"DD d MM yy",
			firstDay: 1,
			showWeek: true, 
			changeYear: true, 
			changeMonth: true
		});
	});
	$(".datepicker").prop("readonly", true);


	$(".datepicker_ddn").each(function()
	{
		$(this).datepicker({
			altField: $(this).next(),
			altFormat: "yy-mm-dd",
			dateFormat:"DD d MM yy",
			firstDay: 1,
			showWeek: true, 
			changeYear: true, 
			changeMonth: true,
			defaultDate:'-10y',
			yearRange : '-22:-10'
		});
	});
	$(".datepicker_ddn").prop("readonly", true);
	 
	 
	$("a[rel='img'], a[rel='img2']").colorbox({ maxWidth:"90%", maxHeight:"90%" });
	$("a[rel='page']").colorbox({ maxWidth:"90%", maxHeight:"90%" });
	$("a[rel='iframe']").colorbox({ iframe:true, maxWidth:"90%", maxHeight:"90%", width:"650px", height:"520px", fixed:true });
	$("a[rel='video'],.video").each(function()
	{
		$(this).data("title", $(this).attr("title"));
	});
	$(document).on("click","a[rel='video'],.video",function(event)
	{
		event.stopPropagation();
		event.preventDefault();
		var e=$(this).attr("href");
		var t=$(this).data("title");
		var m= "https://www.youtube-nocookie.com/watch?v="+e;

		if(isMobile.any()) open(m,"_self");
		else
		{
			$.colorbox(
				{
					html:"<div class='youtube_player' videoID='"+e+"' width='640' height='360' theme='light' rel='0' controls='1' showinfo='0' autoplay='1'></div>",
					title:t,
					onComplete:function()
					{
						(tarteaucitron.job = tarteaucitron.job || []).push('youtube');
						$.colorbox.resize({ width:682, height:435 });
					}
				}
			);
		}
	});

	$("#slider_accueil").CJSlider({ boutonsPagination:true, duree:500, pause:8000, effet:"fondu2", stopOnMouseOver:true, navigation: true });
	
	$(".slider_galerie").each(function(index)
	{
		$(this).find("> div:first-child").CJSlider({ boutonsPagination:false, effet:"fondu2", pause:5000, duree:200, navigation:true, miniatures:true, miniaturesConteneur:$($(".slider_galerie_miniatures").get(index))});
	});
	
	$("#actualites .slider").CJSlider({ duree:1000, pause:8000, effet:"slide", direction:"bas", stopOnMouseOver:true, effetjq:"easeInOutQuart" });
	
	$(document).on("click", ".burger", function(e)
	{
		e.preventDefault();

		$("body").toggleClass("nav-open nav-close");
 	});

 	$(document).on("click", "#menu > ul > li > a", function(e)
 	{
		if($(this).attr("href").indexOf("#") != -1) $("body").toggleClass("nav-open nav-close");
 	});
});

/*Dialog*/
var Dialog = function(titre, message, choix)
{
	if(titre == "")
	{
		if(choix != undefined && Object.keys(choix).length > 1)
		{
			titre = "Confirmation";
		}
		else{
			titre = "Alert";
		}
	}
	
	if(titre == "Alert")
	{
		ico = "alert";
	}
	else if(titre == "Erreur")
	{
		ico = "erreur";
	}
	else
	{
		ico = "information";
	}
	
	if(choix == undefined)
	{
		choix = { "Ok":function(){ $(this).dialog("destroy"); } };
	}
	
	DialogClose();
	
	$("<table title='"+titre+"'><tr><td valign='middle'><span class='ico_32 "+ico+"' /></td><td align='left' valign='middle'>"+message+"</td></tr></table>").dialog({
		resizable: false,
		width: 450,
		height: 160,
		modal: true,
		buttons: choix,
		close: function(){ $(this).remove(); }
	});
}

var DialogClose = function()
{
	$(".ui-dialog").remove();
	$(".ui-dialog").dialog("destroy");
}
