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 $ = jQuery.noConflict();
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()
{
	// 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");
						}
					});
					
				}
			});
		}
	});
	//----------------------------
	/*var zindex = 10;

    $("div.card").click(function(e) {
        e.preventDefault();

        var isShowing = false;

        if ($(this).hasClass("show")) {
            isShowing = true
        }

        if ($("div.cards").hasClass("showing")) {
            // a card is already in view
            $("div.card.show")
                .removeClass("show");

            if (isShowing) {
                // this card was showing - reset the grid
                $("div.cards")
                    .removeClass("showing");
            } else {
                // this card isn't showing - get in with it
                $(this)
                    .css({
                        zIndex: zindex
                    })
                    .addClass("show");

            }

            zindex++;

        } else {
            // no cards in view
            $("div.cards")
                .addClass("showing");
            $(this)
                .css({
                    zIndex: zindex
                })
                .addClass("show");

            zindex++;
        }

    });*/
    
	$(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 / largeur * 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:800, maxHeight:600 });
	$("a[rel='page']").colorbox({ width:"480px", height:"500px" });
	$("a[rel='iframe']").colorbox({ iframe:true, width:"560px", height:"560px" });
	$("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");

		if(isMobile.any()) open(e,"_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_1 > 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("close"); } };
	}
	
	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");
}
