
AOS.init({ once: true });

// custom-header-dropdown
$(document).on('click', '.nav-link', function (e) {
  console.log('here');
  if (window.matchMedia("(max-width: 991px)").matches) {
    if ($(this).closest('.nav-item').find('.dropdown').css('display') == 'none') {
      $('.dropdown').css("display", "none");
      $(this).closest('.nav-item').find('.dropdown').css("display", "block");
    } else {
      $('.dropdown').css("display", "none");
    }
  }
});
// custom-header-dropdown

// toggle password
$(".toggle-password").click(function () {
  $(this).toggleClass("fa-eye fa-eye-slash");
  var input = $($(this).attr("toggle"));
  if (input.attr("type") == "password") {
    input.attr("type", "text");
  } else {
    input.attr("type", "password");
  }
});
// toggle password
$(document).ready(function () {
  $("#currentYear").text(new Date().getFullYear());
});
// slider
$('.banner-slides').owlCarousel({
  loop: true,
  margin: 0,
  animateOut: 'fadeOut',
  animateIn: 'fadeIn',
  nav: false,
  dots: false,
  autoplay: false,
  autoplaySpeed: 5000,
  autoplayTimeout: 5000,
  autoplayHoverPause: false,
  mouseDrag: true,
  smartSpeed: 250,
  navText: [
    '<i class="far fa-chevron-left" aria-hidden="true"></i>',
    '<i class="far fa-chevron-right" aria-hidden="true"></i>'
  ],
  responsiveClass: true,
  responsive: {
    0: {
      items: 1
    },
    575: {
      items: 1
    },
    767: {
      items: 1
    },
    991: {
      items: 1
    },
    1199: {
      items: 1
    },
    1399: {
      items: 1
    }
  }
});

$('.caterogy-slider').owlCarousel({
  loop: true,
  margin: 0,
  animateOut: 'fadeOut',
  animateIn: 'fadeIn',
  nav: false,
  dots: false,
  autoplay: false,
  autoplaySpeed: 5000,
  autoplayTimeout: 5000,
  autoplayHoverPause: false,
  mouseDrag: true,
  smartSpeed: 250,
  navText: [
    '<i class="far fa-chevron-left" aria-hidden="true"></i>',
    '<i class="far fa-chevron-right" aria-hidden="true"></i>'
  ],
  responsiveClass: true,
  responsive: {
    0: {
      items: 1
    },
    575: {
      items: 2
    },
    767: {
      items: 2
    },
    991: {
      items: 3
    },
    1199: {
      items: 4
    },
    1399: {
      items: 4
    }
  }
});

$('.products-slider').owlCarousel({
  loop: true,
  margin: 30,
  animateOut: 'fadeOut',
  animateIn: 'fadeIn',
  nav: false,
  dots: true,
  autoplay: false,
  autoplaySpeed: 5000,
  autoplayTimeout: 5000,
  autoplayHoverPause: false,
  mouseDrag: true,
  smartSpeed: 250,
  navText: [
    '<i class="far fa-chevron-left" aria-hidden="true"></i>',
    '<i class="far fa-chevron-right" aria-hidden="true"></i>'
  ],
  responsiveClass: true,
  responsive: {
    0: {
      items: 1
    },
    575: {
      items: 2
    },
    767: {
      items: 2
    },
    991: {
      items: 3
    },
    1199: {
      items: 4
    },
    1399: {
      items: 4
    }
  }
});

$('.brand-slides').owlCarousel({
  loop: true,
  margin: 30,
  animateOut: 'fadeOut',
  animateIn: 'fadeIn',
  nav: false,
  dots: false,
  autoplay: false,
  autoplaySpeed: 5000,
  autoplayTimeout: 5000,
  autoplayHoverPause: false,
  mouseDrag: true,
  smartSpeed: 250,
  navText: [
    '<i class="far fa-chevron-left" aria-hidden="true"></i>',
    '<i class="far fa-chevron-right" aria-hidden="true"></i>'
  ],
  responsiveClass: true,
  responsive: {
    0: {
      items: 1
    },
    575: {
      items: 2
    },
    767: {
      items: 2
    },
    991: {
      items: 3
    },
    1199: {
      items: 4
    },
    1399: {
      items: 4
    }
  }
});

$('.testimonial-slides').owlCarousel({
  loop: true,
  margin: 0,
  animateOut: 'fadeOut',
  animateIn: 'fadeIn',
  nav: false,
  dots: false,
  autoplay: false,
  autoplaySpeed: 5000,
  autoplayTimeout: 5000,
  autoplayHoverPause: false,
  mouseDrag: true,
  smartSpeed: 250,
  navText: [
    '<i class="far fa-chevron-left" aria-hidden="true"></i>',
    '<i class="far fa-chevron-right" aria-hidden="true"></i>'
  ],
  responsiveClass: true,
  responsive: {
    0: {
      items: 1
    },
    575: {
      items: 1
    },
    767: {
      items: 1
    },
    991: {
      items: 1
    },
    1199: {
      items: 1
    },
    1399: {
      items: 1
    }
  }
});

$('.aboutPage-testimonial').owlCarousel({
  loop: true,
  margin: 0,
  animateOut: 'fadeOut',
  animateIn: 'fadeIn',
  nav: true,
  dots: false,
  autoplay: false,
  autoplaySpeed: 5000,
  autoplayTimeout: 5000,
  autoplayHoverPause: false,
  mouseDrag: true,
  smartSpeed: 250,
  navText: [
    '<i class="fa-solid fa-arrow-left" aria-hidden="true"></i>',
    '<i class="fa-solid fa-arrow-right" aria-hidden="true"></i>'
  ],
  responsiveClass: true,
  responsive: {
    0: {
      items: 1
    },
    575: {
      items: 1
    },
    767: {
      items: 2
    },
    991: {
      items: 2
    },
    1199: {
      items: 2
    },
    1399: {
      items: 2
    }
  }
});
// slider

//Scroll event
$(window).scroll(function () {
  var scrolled = $(window).scrollTop();
  if (scrolled > 200) $('.go-top').fadeIn('slow');
  if (scrolled < 200) $('.go-top').fadeOut('slow');
});
//Scroll event

//Click event
$('.go-top').click(function () {
  $("html, body").animate({ scrollTop: "0" }, 500);
});
//Click event

// sticky-header
// window.onscroll = function () { myFunction() };
// var header = document.getElementById("myHeader");
// var sticky = header.offsetTop;
// function myFunction() {
//   if (window.pageYOffset > sticky) {
//     header.classList.add("sticky");
//   } else {
//     header.classList.remove("sticky");
//   }
// }
// sticky-header

// counter js start
$.fn.jQuerySimpleCounter = function (options) {
  var settings = $.extend({
    start: 0,
    end: 100,
    easing: 'swing',
    duration: 400,
    complete: ''
  }, options);

  var thisElement = $(this);

  $({ count: settings.start }).animate({ count: settings.end }, {
    duration: settings.duration,
    easing: settings.easing,
    step: function () {
      var mathCount = Math.ceil(this.count);
      thisElement.text(mathCount);
    },
    complete: settings.complete
  });
};

$('#number1').jQuerySimpleCounter({ end: parseInt($('#number1').text()), duration: 3000 });
$('#number2').jQuerySimpleCounter({ end: parseInt($('#number2').text()), duration: 3000 });
$('#number3').jQuerySimpleCounter({ end: parseInt($('#number3').text()), duration: 2000 });
$('#number4').jQuerySimpleCounter({ end: parseInt($('#number4').text()), duration: 2000 });
// counter js end

// quantity js start
$(document).on('click', '.quantity-left-minus', function () {
  var sub_qty = parseInt($(this).closest('.numberone').find('input').val());
  if (sub_qty > 1) {
    $(this).closest('.numberone').find('input').val(sub_qty - 1);
    $(this).closest('.numberone').find('input').trigger('change');
  }
});

$(document).on('click', '.quantity-right-plus', function () {
  var add_qty = parseInt($(this).closest('.numberone').find('input').val());
  var max_qty = $(this).closest('.numberone').find('input').attr("max");
  if (add_qty < max_qty) {
    $(this).closest('.numberone').find('input').val(add_qty + 1);
    $(this).closest('.numberone').find('input').trigger('change');
  }
});
// quantity js start

// product-detail multi img slider
$(document).ready(function () {
  var slider = $("#slider");
  var thumb = $("#thumb");
  var slidesPerPage = 4; //globaly define number of elements per page
  var syncedSecondary = true;
  slider.owlCarousel({
    items: 1,
    slideSpeed: 2000,
    nav: false,
    autoplay: false,
    dots: false,
    loop: true,
    responsiveRefreshRate: 200
  }).on('changed.owl.carousel', syncPosition);
  thumb
    .on('initialized.owl.carousel', function () {
      thumb.find(".owl-item").eq(0).addClass("current");
    })
    .owlCarousel({
      items: slidesPerPage,
      margin: 10,
      dots: false,
      nav: true,
      item: 4,
      smartSpeed: 200,
      slideSpeed: 500,
      slideBy: slidesPerPage,
      navText:
        ['<i class="far fa-chevron-left" aria-hidden="true"></i>',
          '<i class="far fa-chevron-right" aria-hidden="true"></i>'],
      responsiveRefreshRate: 100
    }).on('changed.owl.carousel', syncPosition2);
  function syncPosition(el) {
    var count = el.item.count - 1;
    var current = Math.round(el.item.index - (el.item.count / 2) - .5);
    if (current < 0) {
      current = count;
    }
    if (current > count) {
      current = 0;
    }
    thumb
      .find(".owl-item")
      .removeClass("current")
      .eq(current)
      .addClass("current");
    var onscreen = thumb.find('.owl-item.active').length - 1;
    var start = thumb.find('.owl-item.active').first().index();
    var end = thumb.find('.owl-item.active').last().index();
    if (current > end) {
      thumb.data('owl.carousel').to(current, 100, true);
    }
    if (current < start) {
      thumb.data('owl.carousel').to(current - onscreen, 100, true);
    }
  }
  function syncPosition2(el) {
    if (syncedSecondary) {
      var number = el.item.index;
      slider.data('owl.carousel').to(number, 100, true);
    }
  }
  thumb.on("click", ".owl-item", function (e) {
    e.preventDefault();
    var number = $(this).index();
    slider.data('owl.carousel').to(number, 300, true);
  });

});
// product-detail multi img slider

// img-zoom js strat
$(".img_producto_container")
  // tile mouse actions
  .on("mouseover", function () {
    $(this)
      .children(".img_producto")
      .css({ transform: "scale(" + $(this).attr("data-scale") + ")" });
  })
  .on("mouseout", function () {
    $(this)
      .children(".img_producto")
      .css({ transform: "scale(1)" });
  })
  .on("mousemove", function (e) {
    $(this)
      .children(".img_producto")
      .css({
        "transform-origin":
          ((e.pageX - $(this).offset().left) / $(this).width()) * 100 +
          "% " +
          ((e.pageY - $(this).offset().top) / $(this).height()) * 100 +
          "%"
      });
  });

// img-zoom js end

// price-range-slider
(function ($) {

  // $('#price-range-submit').hide();

  $("#min_price,#max_price").on('change', function () {

    $('#price-range-submit').show();

    var min_price_range = parseInt($("#min_price").val());

    var max_price_range = parseInt($("#max_price").val());

    if (min_price_range > max_price_range) {
      $('#max_price').val(min_price_range);
    }

    $("#slider-range").slider({
      values: [min_price_range, max_price_range]
    });

  });


  $("#min_price,#max_price").on("paste keyup", function () {

    $('#price-range-submit').show();

    var min_price_range = parseInt($("#min_price").val());

    var max_price_range = parseInt($("#max_price").val());

    if (min_price_range == max_price_range) {

      max_price_range = min_price_range + 100;

      $("#min_price").val(min_price_range);
      $("#max_price").val(max_price_range);
    }

    $("#slider-range").slider({
      values: [min_price_range, max_price_range]
    });

  });

  $(function () {
    $("#slider-range").slider({
      range: true,
      orientation: "horizontal",
      min: 0,
      max: 4500,
      values: [0, 4500],
      step: 100,

      slide: function (event, ui) {
        if (ui.values[0] == ui.values[1]) {
          return false;
        }

        $("#min_price").val(ui.values[0]);
        $("#max_price").val(ui.values[1]);
      }
    });

    $("#min_price").val($("#slider-range").slider("values", 0));
    $("#max_price").val($("#slider-range").slider("values", 1));

  });

  $("#slider-range,#price-range-submit").click(function () {

    var min_price = $('#min_price').val();
    var max_price = $('#max_price').val();

    $("#searchResults").text("From " + "$" + min_price + " " + "-" + " " + "To" + " " + "$" + max_price + ".");
  });
  $("#searchResults").text("From $0 - To $1050.");

})(jQuery);
// price-range-slider

// sticky-cart-summer
window.onscroll = function () {
  handleStickyHeader();
  handleStickyOrderSummary();
};

function handleStickyHeader() {
  var header = document.getElementById("myHeader");
  var sticky = header.offsetTop;

  if (window.pageYOffset > sticky) {
    header.classList.add("sticky");
  } else {
    header.classList.remove("sticky");
  }
}

function handleStickyOrderSummary() {
  let summary = document.getElementById("orderSummary");
  let parent = document.querySelector(".section-cart");
  let stickyOrder = parent.offsetTop;

  if (window.pageYOffset > stickyOrder) {
    summary.style.position = "fixed";
    summary.style.top = "15%";
  } else {
    summary.style.position = "static";
    summary.style.top = "";
  }
}


// sticky-cart-summer