(function ($) {
	'use strict';

	// Tooltips
	$(document).ready(function(){
		$('[data-toggle="tooltip"]').tooltip();
	});
	// Preloader js
	$(window).on('load', function () {
		$('.preloader').fadeOut(700);
	});

	$('#selectPays').selectpicker();

	$('#reset').on('click', function () {
		   $('#SelectFormJurisType').find('option:selected').removeAttr('selected');
		   $('#SelectFormJurisJuridiction').find('option:selected').removeAttr('selected');
		   $('#SelectFormJurisPays').find('option:selected').removeAttr('selected');
		   $('#InputFormJurisOhadata').removeAttr('value');
		   $('#InputFormJurisReference').removeAttr('value');
		   $('#InputFormJurisMotsCles').removeAttr('value');

		   $('#InputFormDoctrineOhadata').removeAttr('value');
		   $('#InputFormDoctrineInitule').removeAttr('value');
		   $('#InputFormDoctrineSource').removeAttr('value');
		   $('#InputFormDoctrineMotsCles').removeAttr('value');
		   $('#SelectFormDoctrineCategorie').find('option:selected').removeAttr('selected');
		   $('#SelectFormDoctrineAuteur').find('option:selected').removeAttr('selected');

	});

	$('#InputFormJurisDateIntervalle').click(function() {
		  if ($(this).is(':checked')) {
			$('#InputFormJurisDate').parent().addClass( "d-none" );
			$('#InputFormJurisDateDebut').parent().removeClass( "d-none" );
			$('#InputFormJurisDateFin').parent().removeClass( "d-none" );
			$('#InputFormJurisDate').val( "" );
		  }
		 else  if ($(this).not(':checked')) {
			$('#InputFormJurisDate').parent().removeClass( "d-none" );
			$('#InputFormJurisDateDebut').parent().addClass( "d-none" );
			$('#InputFormJurisDateFin').parent().addClass( "d-none" );
			$('#InputFormJurisDateDebut').val( "" );
			$('#InputFormJurisDateFin').val( "" );
		  }
	  });

	$("#signupConditions").click( function(){
	   if( $(this).is(':checked') )
	   {
	   		$("#signupConditions + a").removeClass("text-warning");
	   		$("#signupConditions + a").addClass("text-success");
		}
	  else if( $(this).not(':checked') )
	  {
	   		$("#signupConditions + a").removeClass("text-success");
	   		$("#signupConditions + a").addClass("text-warning");
	   }
	});

	/*$("p.countdown").ready(function() {
	 var count = 10;
	   var countdown = setInterval(function(){
	     $("#countdownstart").html(+ count);
	     if (count == 1) {
	       clearInterval(countdown);
	       window.open('/connexion.html', "_self");
	     }
	     count--;
	  }, 1000);
	});*/

	// Sticky Menu
	$(window).scroll(function () {
		var height = $('.top-header').innerHeight();
		if ($('header').offset().top > 10) {
			$('.top-header').addClass('hide');
			$('.navigation').addClass('nav-bg');
			$('.navigation').css('margin-top', '-' + height + 'px');
		} else {
			$('.top-header').removeClass('hide');
			$('.navigation').removeClass('nav-bg');
			$('.navigation').css('margin-top', '-' + 0 + 'px');
		}
	});


	// Background-images
	$('[data-background]').each(function () {
		$(this).css({
			'background-image': 'url(' + $(this).data('background') + ')',
			'background-size': 'cover',
			'background-repeat': 'no-repeat'
		});
	});

	//Hero Slider
	$('.hero-slider').slick({
		autoplay: true,
		autoplaySpeed: 7500,
		pauseOnFocus: false,
		pauseOnHover: false,
		infinite: true,
		arrows: true,
		fade: true,
		speed: 2000,
		prevArrow: '<button type=\'button\' class=\'prevArrow\'><i class=\'fas fa-angle-left fa-2x\'></i></button>',
		nextArrow: '<button type=\'button\' class=\'nextArrow\'><i class=\'fas fa-angle-right fa-2x\'></i></button>',
		dots: true,
		swipeToSlide:true,

	});
	/*$('.hero-slider').slickAnimation();*/

	$('.hero-slider').on('beforeChange', function(event, slick, currentSlide, nextSlide){
		var CurrentSlideDom=$(slick.$slides.get(nextSlide));
		/*$('.hero-section[data-background]').css({
			'background-image': 'url(' + CurrentSlideDom.attr("data-background-item") + ')',
		});*/

		var json_img = CurrentSlideDom.attr("data-background-item").match(/.*\//);
		$.getJSON(json_img + 'img.json', function(entries) {
		var entry = entries[Math.floor(Math.random()*entries.length)];
			$('.hero-section[data-background]').css({
				'background-image': 'url(' + entry + ')',
				'opacity': 0.2,
			});
			$('.hero-section[data-background]').animate({opacity: 1}, 2500);
		});
	});


	$('.cust-slider').slick({
		autoplay: true,
		autoplaySpeed: 7500,
		pauseOnFocus: false,
		pauseOnHover: false,
		infinite: true,
		arrows: true,
		slidesToShow: 1,
		slidesToScroll: 1,
		prevArrow: '<button type=\'button\' class=\'prevArrow\'><i class=\'fad fa-angle-left fa-2x\'></i></button>',
		nextArrow: '<button type=\'button\' class=\'nextArrow\'><i class=\'fad fa-angle-right fa-2x\'></i></button>',
		dots: true,
		responsive: [
		    {
		      breakpoint: 1024,
		      settings: {
		        slidesToShow: 1,
		        slidesToScroll: 1,
		        infinite: true,
		        dots: true
		      }
		    },
		    {
		      breakpoint: 960,
		      settings: {
		        slidesToShow: 1,
		        slidesToScroll: 1
		      }
		    },
		    {
		      breakpoint: 600,
		      settings: {
		        slidesToShow: 1,
		        slidesToScroll: 1
		      }
		    },
		    {
		      breakpoint: 480,
		      settings: {
		        slidesToShow: 1,
		        slidesToScroll: 1
		      }
		    }
  ]
	});

	/*$('.cust-slider').slickAnimation();*/

	// venobox popup
	$(document).ready(function () {
		$('.venobox').venobox({
			titleattr: 'data-title',
			numeratio: true,
			infinigall : true,
			spinner:'cube-grid',
			spinColor:'#ffbc3b',
			share: ['facebook', 'twitter', 'linkedin', 'pinterest', 'download']
		});
	});


	// filter
	$(document).ready(function () {
		var containerEl = document.querySelector('.filtr-container');
		var filterizd;
		if (containerEl) {
			filterizd = $('.filtr-container').filterizr({});
		}
		//Active changer
		$('.filter-controls li').on('click', function () {
			$('.filter-controls li').removeClass('active');
			$(this).addClass('active');
		});
	});

	//  Count Up
	function counter() {
		var oTop;
		if ($('.count').length !== 0) {
			oTop = $('.count').offset().top - window.innerHeight;
		}
		if ($(window).scrollTop() > oTop) {
			$('.count').each(function () {
				var $this = $(this),
					countTo = $this.attr('data-count');
				$({
					countNum: $this.text()
				}).animate({
					countNum: countTo
				}, {
					duration: 1000,
					easing: 'swing',
					step: function () {
						$this.text(Math.floor(this.countNum));
					},
					complete: function () {
						$this.text(this.countNum);
					}
				});
			});
		}
	}
	$(window).on('scroll', function () {
		counter();
	});
	//  Go top

	if ($('#back-to-top').length) {
	    var scrollTrigger = 100, // px
	        backToTop = function() {
	            var scrollTop = $(window).scrollTop();
	            if (scrollTop > scrollTrigger) {
	                $('#back-to-top').addClass('show');
	            } else {
	                $('#back-to-top').removeClass('show');
	            }
	        };
	    backToTop();
	    $(window).on('scroll', function() {
	        backToTop();
	    });
	    $('#back-to-top').on('click', function(e) {
	        e.preventDefault();
	        $('html,body').animate({
	            scrollTop: 0
	        }, 700);
	    });
	}

	$('.texte-article-doctrine').click(function(){
		var langue = $(this).data("langue");
		var ref_article = $(this).data("article");
		var rubrique = $(this).data("rubrique");
		$.ajax({
			type: 'GET',
			url: '/ajax.php',
			dataType:"json",
			data: {"article": ref_article, "rubrique":rubrique},
			success: function(res) {
				console.log(res);
				$('.modal-title').text(res['titre']);

				if(res['format']=="texte")
				{
					var texte_article = res['article'].replace(/(\r\n|\n|\r)/gm, "<br>");
					$('.modal-body').html(texte_article);
				}
				else if(res['format']=="html")
				{
					var texte_article = res['article'];
					$('.modal-body').html(texte_article);
				}
				//$('.modal-footer').html('<a href="#" class="copy-article"><i class="bi bi-copy"></i></a>');
				$('.modal-footer').html("<span class=\"text-secondary font-italic\" style=\"font-style:italic;\">"+res['nom_texte']+"</span>");

				$('#texteArticle').modal('show');

			},
			error:function(request, status, error) {
				console.log("ajax call went wrong:" + request.responseText + request + status + error);
			}
		});
	});



})(jQuery);