/*tarteaucitron.init({
    //"hashtag": "#tarteaucitron",
    "highPrivacy": false, 
    "orientation": "top",
    "adblocker": false,
    "showAlertSmall": false,
    "cookieslist": false, 
    "removeCredit": false,
    "handleBrowserDNTRequest": false,
    "moreInfoLink": true,
    //"cookieDomain": ".domaine.tld"
});*/

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()
{
	// 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);
	});

	$('.compteur').each(function () {
	  var $this = $(this);
	  jQuery({ Counter: 0 }).animate({ Counter: $this.text() }, {
	    duration: 5000,
	    easing: 'swing',
	    step: function () {
	      $this.text(Math.ceil(this.Counter));
	    }
	  });
	});

	/* -------- Début (Page Formation) ------- */
	$(document).on("click", "#tarif > div > ul > li", function(){
		var freros = $(this).prevAll().length;
		$(".tarif-tab"+freros).css({ 'border-bottom':'4px solid #ededed', 'background-color':'#ededed' }).siblings('li').css({ 'border-bottom':'4px solid rgba(255,255,255,1)', 'background-color':'#c9c9c9' });
		$(".tarif-nav"+freros).css('display','block').siblings('div').css('display','none');
	});	
	/* ---------- Fin ---------- */
	
	//----------------------------
	$(document).ready(function(){
	   setInterval(Cursor_Captcha,3000);
	});
	function Cursor_Captcha() {
		if($('#captchagc').hasClass('valid'))
		{
			$('.cursor-captcha').hide();
		}
		else
		{
			$('.cursor-captcha').show();
			$('.cursor-captcha').css({left:'25px'});
			$('.cursor-captcha').animate({left: '205px'}, 900);
		}
	}

	$("#captchagc > img.fav").draggable({ revert: true, containment: "parent" });
	$("#captchagc > img.fav + div").droppable({ 
		accept: "#captchagc > img.fav", 
		activeClass: "accept", 
		hoverClass: "hover", 
		drop: function(event, ui)
		{
			$("#captchagc").addClass("valid");
			$('.cursor-captcha').hide();
			$.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");
							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()
	{
		$(this).parent().addClass("select").siblings().removeClass("select");
	});

	$(window).on("hashchange",function(){
		setTimeout(function(){
			if(location.hash != "" && location.hash != "#_=_" && $("[data-ancre='"+(location.hash.substring(1))+"']").length > 0) $("html,body").animate({ "scrollTop":$("[data-ancre='"+location.hash.substring(1)+"']").offset().top-($(window).width() <= 860 ? 0 : $("#site > #header").height()) }, 1000);
			if(location.hash == "#bienvenue") $("html,body").animate({ "scrollTop":0 });
		},1000);
	});
	$(window).trigger("hashchange");
	$(document).on("click", "a[href^='./#'],a[href^='/#']", function()
	{
		$(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");
			$('#logo img').attr("src", "img/logo-groupe-acn-blanc.png");
		}
		else if(scroll < 120 && $('#header').hasClass("scroll"))
		{
			$('#header').removeClass("scroll");
			$('#logo img').attr("src", "img/logo-groupe-acn.png");

		}
	});


	$(".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: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" });
	//$("#slider_avis").CJSlider({ boutonsPagination:true, duree:500, pause:8000, effet:"slide", direction:"gauche", stopOnMouseOver:true, effetjq:"easeInOutQuart" });
	$("#slide_avis").slick({
		slidesToShow: 3,
		swipeToSlide: true,
		arrows: true,
		infinite: false,
		responsive: [
		  {
			breakpoint: 860,
			settings: {
			  arrows: false,
			  centerMode: false,
			  centerPadding: "40px",
			  slidesToShow: 1.2,
			},
		  },
		],
	  });


	$(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 && titre != "Chargement")
	{
		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,
		closeOnEscape:(titre == "Chargement" ? 0 : 1),
		open: function(event, ui)
		{
	        if(titre == "Chargement") $(".ui-dialog-titlebar-close").hide();
	    },
		close: function(){ $(this).remove(); }
	});
}

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