// Aos
AOS.init();

setTimeout(() => {
  $(".loading").fadeOut(1000);
}, 3500);

window.onload = function () {
  $(".loading").fadeOut(1000);
  setTimeout(() => {
    $(".header-pages").addClass("active");
  }, 300);
};



$(".sub-question h2").click(function(){
    $(this).next().slideToggle();
    $(this).toggleClass("active");

})

lightGallery(document.getElementById("lightgallery"), {
  thumbnail: true,
  selector: ".image-item",
});

//silder-index
$("#slider-1").owlCarousel({
  loop: false,
  margin: 0,
    video:true,
  nav: true,
  items: 1,
  autoplayTimeout: 5000,
  autoplayHoverPause: true,
  rtl: true,
//   autoplay: true,
  dots: false,
  smartSpeed: 2500,
  responsiveClass: true,
  responsive: {
    1400: {
      item: 1,
    },
  },
});

//silder-clients
$("#slider-clients").owlCarousel({
  loop: true,
  margin: 0,
  nav: true,
  items: 1,
  autoplayTimeout: 5000,
  autoplayHoverPause: true,
  rtl: true,
  autoplay: true,
  dots: true,
  smartSpeed: 2500,
  responsiveClass: true,
  responsive: {
    1400: {
      item: 1,
    },
  },
});

//silder-partners
$(".slider-partners").owlCarousel({
  loop: true,
  margin: 20,
  nav: true,
  items: 1,
  autoplayTimeout: 5000,
  autoplayHoverPause: true,
  rtl: true,
  autoplay: false,
  dots: false,
  smartSpeed: 2500,

  responsiveClass: true,
  responsive: {
    0: {
      items: 1,
    },
    600: {
      items: 1,
    },
    1000: {
      items: 1,
    },
  },
});

$(".remove_mune").click(function () {
  $("#menu-div").removeClass("active");
  $(".bg_menu").removeClass("active");
});

function open() {
  $(".navicon").addClass("is-active");
  $("#menu-div").addClass("active");
  $("#times-ican").addClass("active");
  $(".bg_menu").addClass("active");
}

function close() {
  $(".navicon").removeClass("is-active");
  $("#menu-div").removeClass("active");
  $("#times-ican").removeClass("active");
  $(".bg_menu").removeClass("active");
  $(".remove-mune").click(function () {
    $("#menu-div").removeClass("active");
    $(".bg_menu").removeClass("active");
    $(".times-ican").removeClass("active");
  });
}

$("#times-ican").click(function () {
  if ($(this).hasClass("active")) {
    close();
  } else {
    open();
  }
});

$(".remove-mune").click(function () {
  $("#menu-div").removeClass("active");
  $(".bg_menu").removeClass("active");
  $(".times-ican").removeClass("active");
  $(".navicon").removeClass("is-active");
});

$("#menu-div a").click(function () {
  e.preventDefault();
});

var $winl = $(window); // or $box parent container
var $boxl = $("#menu-div, #times-ican");
$winl.on("click.Bst", function (event) {
  if (
    $boxl.has(event.target).length === 0 && //checks if descendants of $box was clicked
    !$boxl.is(event.target) //checks if the $box itself was clicked
  ) {
    close();
  }
});



// counter


if ($('.counter').length) {
var a = 0;
$(window).scroll(function () {
  var oTop = $(".counter-box").offset().top - window.innerHeight;
  if (a == 0 && $(window).scrollTop() > oTop) {
    $(".counter").each(function () {
      var $this = $(this),
        countTo = $this.attr("data-number");
      $({
        countNum: $this.text(),
      }).animate(
        {
          countNum: countTo,
        },

        {
          duration: 2550,
          easing: "swing",
          step: function () {
            //$this.text(Math.ceil(this.countNum));
            $this.text(Math.ceil(this.countNum).toLocaleString("en"));
          },
          complete: function () {
            $this.text(Math.ceil(this.countNum).toLocaleString("en"));
            //alert('finished');
          },
        }
      );
    });
    a = 1;
  }
});

const animationDuration = 4000;

const frameDuration = 1000 / 60;

const totalFrames = Math.round(animationDuration / frameDuration);

const easeOutQuad = (t) => t * (2 - t);

const animateCountUp = (el) => {
  let frame = 0;
  const countTo = parseInt(el.innerHTML, 10);

  const counter = setInterval(() => {
    frame++;

    const progress = easeOutQuad(frame / totalFrames);

    const currentCount = Math.round(countTo * progress);

    if (parseInt(el.innerHTML, 10) !== currentCount) {
      el.innerHTML = currentCount;
    }

    if (frame === totalFrames) {
      clearInterval(counter);
    }
  }, frameDuration);
};

const countupEls = document.querySelectorAll(".timer");
countupEls.forEach(animateCountUp);

$(".animated-progress span").each(function () {
  $(this).animate(
    {
      width: $(this).attr("data-progress") + "%",
    },
    2100
  );
  $(this).text($(this).attr("data-progress") + "%");
});

}
// ----------------------
// var youtube = $('.youtube');
// var check_active = youtube.closest('.owl-item');
// console.log(check_active);
// console.log(check_active.hasClass('active'));
// if(check_active.hasClass('active'))
// {
//   alert('youtube');
// }

// $("#slider-1").on('translate.owl.carousel', function (e) {
//   $('.owl-item .item iframe').each(function () {
//     console.log('iframe');
//     // pause playing video - after sliding
//     var src = this.src
//     this.src = src;
//   });
// });

$("#slider-1").on('translated.owl.carousel', function (e) {
  // check: does the slide have a video?
  console.log($('.owl-item.active').find('iframe').length);
  if ($('.owl-item.active .youtube .sub-slider-header').find('iframe').length !== 0) {
    console.log('active');
    // play video in active slide
    var src = $('.owl-item .youtube .sub-slider-header iframe').attr('src');
    var new_src = src.split("?");
    $('.owl-item .youtube .sub-slider-header iframe').attr('src' , new_src[0]);
    var src = $('.owl-item.active .youtube .sub-slider-header iframe').attr('src');
    $('.owl-item.active .youtube .sub-slider-header iframe').attr('src' , src+"?autoplay=1");
  } else {
    console.log('no active');
    var src = $('.owl-item .youtube .sub-slider-header iframe').attr('src');
    var new_src = src.split("?");
    $('.owl-item .youtube .sub-slider-header iframe').attr('src' , new_src[0]);
  }
});