/*** Pencil Banner JS ***/
const announcementBar = () => {
  let announcementEle = document.querySelector('.sample-slider'),
  swiperOptions = JSON.parse(announcementEle.dataset.sliderOptions);
  swiper = new Swiper(announcementEle,swiperOptions);
  announcementEle.addEventListener('mouseover', () => {
    swiper.autoplay.stop();
  })
  announcementEle.addEventListener('mouseleave', () => {
    swiper.autoplay.start();
  })
}
window.addEventListener('DOMContentLoaded', () => {
  if(jQuery('.sample-slider').length > 0) {
    announcementBar();
  }
})
/*** Pencil Banner JS END ***/
jQuery(document).ready(function($) {
  /*** AOS JS ***/
  if (jQuery(window).width() > 768) {
    AOS.init();
  }
  /*** Video Play / Pause JS ***/
  jQuery('.custom-video').click(function() {
      console.log('clicked')
      this.paused ? this.play() : this.pause();
      jQuery(this).toggleClass('active');
  });
  /*** SizeChart Popup JS ***/
	jQuery('.size-chart').click(function(){
    jQuery('body').addClass('popup-open');
  });
  jQuery('.popup-inner .popup-close').click(function(){
      jQuery('body').removeClass('popup-open');
  });
  /*** Sidebar Toggle JS ***/
  jQuery('.sidebar-toggle span').click(function(){
      jQuery('body').toggleClass('sidebar-hide');
  });
  /*** Search Popup JS ***/
  jQuery('.search-icon').click(function(){
    jQuery('body').addClass('search-open');
  });
  jQuery('.close-search').click(function(){
    jQuery('body').removeClass('search-open');
  });
  /*** Quickview Popup JS ***/
  jQuery(' .collection-item .collection-img .button').click(function(){
    jQuery('body').addClass('quickview-open');
  });
  jQuery('.quick-view-close').click(function(){
    jQuery('body').removeClass('quickview-open');
  });
  /*** Mobile Menu JS ***/
  jQuery('.mobile-icon a').click(function(){
    jQuery('body').toggleClass('navigation-open');
  });
  /*** TreeView JS ***/
  if (jQuery(window).width() < 1024) {
    jQuery(".tree").treeview({
      collapsed: true,
    	animated: "medium down"
    });
  }
  /*** Scroll On Has JS ***/
  var header_height = jQuery(".header-block").outerHeight() + 20; 
  if(location.href.indexOf('#')>0){
    var val = location.href;
    var myString = val.substr(val.indexOf("#"));
    setTimeout(function (){
      var position = jQuery(myString).offset().top - header_height;
      jQuery("body, html").animate({
        scrollTop: position
      },"slow");
    }, 500);
  }
  jQuery('body').on('click', 'a[href*="#"]', function(e){
      var val = jQuery(this).attr('href');
      e.preventDefault();
      var myString = val.substr(val.indexOf("#"));
      var position = jQuery(myString).offset().top - header_height;
      jQuery("body, html").animate({
        scrollTop: position
      },"slow");
  });
  /*** Scroll Top JS ***/
  jQuery(".ScrollToTop").click(function() {
    jQuery("html, body").animate({ scrollTop: 0 }, "slow");
    return false;
  });
  jQuery(window).scroll(function() {
    if (jQuery(this).scrollTop() - 200 > 0) {
      jQuery('.ScrollToTop').stop().slideDown('fast'); // show the button
    } else {
      jQuery('.ScrollToTop').stop().slideUp('fast'); // hide the button
    }
    /*** sticky cart open ***/
    if (jQuery('.featured-collection .section-title').hasClass('aos-animate')){
      jQuery('.sticky-cart').addClass('active'); 
    } else {
      jQuery('.sticky-cart').removeClass('active');
    }
  });
  /*** Resize JS ***/
  jQuery(window).resize(function() {
    if (jQuery(window).width() > 768) {
      setTimeout(function(){
        AOS.init();
      });
    }
    if (jQuery(window).width() < 1024) {
      if (jQuery('.tree').length == 0) {
        jQuery(".tree").treeview({
          collapsed: true,
          animated: "medium down"
        });
      }
    }
  }); // Resize JS END
}); // Document Ready END