$(document).ready(function () {
  $(this).scrollTop(0);
  const $sideMnuBx = $(".hdrBtmRow");
  const $hdrPrfilBx = $(".hdrPrfilBx");
  const $blgHdrMnu = $(".blgHdrMnu");
  const $resultFltr = $(".resultFltr");
  const $sortLstBx = $(".sortLstBx");
  const $dashCmntMnu = $(".dashCmntMnu");

  var rOffset = $(".hdrTopRow").offset();

  // new
  const $hdrMnu = $(".hdrMnu");

  /***********mouseup********/
  $(document).mouseup((ev) => {
    if ($(".hdrBtmRow").hasClass("opened")) {
      if (!$sideMnuBx.is(ev.target) && $sideMnuBx.has(ev.target).length === 0) {
        $(".hdrBtmRow").removeClass("opened");
        $("body").removeClass("noScroll hidOverflow");
        $(".catSubBx").slideUp(100).removeClass("open");
        $(".catSubList").fadeOut(100);
        $(".catSubLnk").removeClass("active");
        $(".subTwoLst").removeClass("open").fadeOut(100);
        $(".subTwoLnk").removeClass("active");
      }
    }
    if ($(".hdrPrfilSub").hasClass("open")) {
      if (
        !$hdrPrfilBx.is(ev.target) &&
        $hdrPrfilBx.has(ev.target).length === 0
      ) {
        $(".hdrPrfilSub").removeClass("open").slideUp(300);
        $(".hdrPrfiLnk").removeClass("open");
      }
    }

    if ($(".blgHdrMnu").hasClass("opened")) {
      if (!$blgHdrMnu.is(ev.target) && $blgHdrMnu.has(ev.target).length === 0) {
        $(".blgHdrMnu").removeClass("opened");
        $("body").removeClass("noScroll");
      }
    }

    if ($(".minPrfilSub").hasClass("open")) {
      if (
        !$hdrPrfilBx.is(ev.target) &&
        $hdrPrfilBx.has(ev.target).length === 0
      ) {
        $(".minPrfilSub").removeClass("open").slideUp(300);
      }
    }

    // new
    if ($(".catSubBx").hasClass("open")) {
      if (!$hdrMnu.is(ev.target) && $hdrMnu.has(ev.target).length === 0) {
        $(".catSubBx").slideUp(100).removeClass("open");
        $("body").removeClass("hidOverflow");
        $(".catSubList").fadeOut(100);
        $(".catSubLnk").removeClass("active");
        $(".subTwoLst").removeClass("open").fadeOut(100);
        $(".subTwoLnk").removeClass("active");
      }
    }

    if ($(".resultFltr").hasClass("open")) {
      if (
        !$resultFltr.is(ev.target) &&
        $resultFltr.has(ev.target).length === 0
      ) {
        $(".resultFltr").removeClass("open");
        $("body").removeClass("noScroll");
      }
    }

    if ($(".sortLstBx ul").hasClass("open")) {
      if (!$sortLstBx.is(ev.target) && $sortLstBx.has(ev.target).length === 0) {
        $(".sortLstBx ul").removeClass("open").slideUp(200);
      }
    }

    if ($(".cmntMnuBx").hasClass("open")) {
      if (
        !$dashCmntMnu.is(ev.target) &&
        $dashCmntMnu.has(ev.target).length === 0
      ) {
        $(".cmntMnuBx").removeClass("open").slideUp(200);
      }
    }
  });

  /******************show-side-bar*******************/
  if ($(".hdrOpnMnu").length) {
    $(".hdrOpnMnu").click(function () {
      $(".hdrBtmRow").addClass("opened");
      $("body").addClass("noScroll");
    });
  }

  if ($(".closeSide").length) {
    $(".closeSide").click(function () {
      $(".hdrBtmRow").removeClass("opened");
      $("body").removeClass("noScroll hidOverflow");
      $(".catSubBx").slideUp(100).removeClass("open");
      $(".catSubList").fadeOut(100);
      $(".catSubLnk").removeClass("active");
      $(".subTwoLst").removeClass("open").fadeOut(100);
      $(".subTwoLnk").removeClass("active");
    });
  }

  /***********show-remove-btn-in-search-form********/
  if ($(".hdrSrchFrm").length) {
    var input = $(".hdrSrchFrm").find("input");
    input.on("keypress", function () {
      $(".mostSrchdBx").slideUp();
      if (input.val()) {
        $(".hdrSrchFrm").find(".rmvSrchInpt").fadeIn();
        $(".relatdRsult").slideDown();
      } else {
        $(".hdrSrchFrm").find(".rmvSrchInpt").fadeOut();
        $(".relatdRsult").slideUp();
      }
    });
    $(".rmvSrchInpt").click(function () {
      input.val("");
      $(".rmvSrchInpt").fadeOut();
      $(".relatdRsult").slideUp();
    });
    input.focus(function () {
      if (!input.val()) {
        $(".hdrSrchFrm").addClass("focused");
        $(".mostSrchdBx").slideDown();
      }
    });
    input.blur(function () {
      $(".hdrSrchFrm").removeClass("focused");
      $(".mostSrchdBx").slideUp();
      $(".relatdRsult").slideUp();
    });
  }

  /********************margin*********************/
  // new
  if ($(".catSubUl").length) {
    var offset = $(".hdrRow").offset();
    $(".catSubUl").css("paddingRight", offset.left);

    // Update on window resize
    $(window).on("resize", function () {
      var offset = $(".hdrRow").offset();
      $(".catSubUl").css("paddingRight", offset.left);
    });
  }

  if ($(window).width() >= 768) {
    $(".marginRght").css("right", rOffset.left);
  }

  /****************audio*****************/
  if ($(".msgAudio").length) {
    $(".msgAudio").each(function () {
      var thisAudio = $(this);
      thisAudio.find(".audioCls").audioPlayer();
    });
  }

  /******************show-sub-menu*******************/
  // new
  if ($(".catSubBx").length) {
    $(".hdrCatLnk").click(function () {
      if (!$(".catSubBx").hasClass("open")) {
        $(".catSubBx").slideDown(300).addClass("open");
        $("body").addClass("hidOverflow");

        $(".closeCatBx").css("right", `calc(100% + 10px)`);

        var heightVar = $(".catSubUl").css("height");
        if ($(window).width() > 991) {
          $(".catSubList").css("height", heightVar);
          $(".subTwoLst").css("height", heightVar);
        } else {
          $(".catSubList").css("height", "auto");
          $(".subTwoLst").css("height", "auto");
        }
        $(window).on("resize", function () {
          if ($(window).width() > 991) {
            $(".catSubList").css("height", heightVar);
            $(".subTwoLst").css("height", heightVar);
          } else {
            $(".catSubList").css("height", "auto");
            $(".subTwoLst").css("height", "auto");
          }
        });
      } else {
        $(".catSubBx").slideUp(300).removeClass("open");
        $("body").removeClass("hidOverflow");
        $(".catSubList").fadeOut(100);
        $(".subTwoLst").removeClass("open").fadeOut(100);
        $(".catSubLnk").removeClass("active");
        $(".subTwoLnk").removeClass("active");
      }
    });

    $(".closeCatBx").click(function () {
      $(".catSubBx").slideUp(300).removeClass("open");
      $("body").removeClass("hidOverflow");
      $(".catSubList").fadeOut(100);
      $(".subTwoLst").removeClass("open").fadeOut(100);
      $(".catSubLnk").removeClass("active");
      $(".subTwoLnk").removeClass("active");
    });
  }

  if ($(".catSubList").length) {
    $(".catSubLnk").click(function () {
      if (!$(this).next(".catSubList").hasClass("open")) {
        $(".catSubList").fadeOut(100).removeClass("open");
        $(".catSubLnk").removeClass("active");
        $(".subTwoLnk").removeClass("active");
        $(".subTwoLst").removeClass("open").fadeOut(100);
        $(this).addClass("active");
        $(this).next(".catSubList").addClass("open").fadeIn(200);

        $(".closeCatBx").css("right", `180%`);
      } else {
        $(this).removeClass("active");
        $(this).next(".catSubList").removeClass("open").fadeOut(200);

        $(".closeCatBx").css("right", `calc(100% + 10px)`);
      }
    });
  }

  if ($(".subTwoLst").length) {
    $(".subTwoLnk").click(function () {
      if (!$(this).next(".subTwoLst").hasClass("open")) {
        $(".subTwoLst").fadeOut(100).removeClass("open");
        $(".subTwoLnk").removeClass("active");
        $(this).addClass("active");
        $(this).next(".subTwoLst").fadeIn(200);

        $(".closeCatBx").css("right", `256%`);
      } else {
        $(this).removeClass("active");
        $(this).next(".subTwoLst").removeClass("open").fadeIn(200);
        $(".closeCatBx").css("right", `180%`);
      }
    });
  }

  $(".opnCmntMnu").click(function () {
    $(this).next(".cmntMnuBx").toggleClass("open").slideToggle(300);
  });

  /********************swiper*********************/
  // new
  if ($(".topSlider").length) {
    var swiper = new Swiper(".topSlider .swiper", {
      spaceBetween: 10,
      slidesPerView: 1,
      grabCursor: true,
      centeredSlides: true,
      loop: true,
      navigation: {
        nextEl: ".topSlider .swiperBtns .next",
        prevEl: ".topSlider .swiperBtns .prev",
      },
      autoplay: {
        delay: 5000,
        pauseOnMouseEnter: true,
      },
      pagination: {
        el: ".topSlider .swiper-pagination",
      },
    });
  }

  $(".specialSec .swiper").each(function () {
    var swiper = new Swiper(this, {
      spaceBetween: 2,
      slidesPerView: "auto",
      grabCursor: true,
      // nextButton: $this.find(".speclSwprBtn .next")[0],
      // prevButton: $this.find(".speclSwprBtn .prev")[0],
    });
  });

  if ($(".relatdSwpr").length) {
    var swiper = new Swiper(".relatdSwpr", {
      spaceBetween: 1,
      slidesPerView: "auto",
      grabCursor: true,
      navigation: {
        nextEl: ".relatdSwpr .swiper-button-next",
        prevEl: ".relatdSwpr .swiper-button-prev",
      },
    });
  }

  if ($(".complmntrySwpr").length) {
    var swiper = new Swiper(".complmntrySwpr", {
      spaceBetween: 1,
      slidesPerView: "auto",
      grabCursor: true,
      navigation: {
        nextEl: ".complmntrySwpr .swiper-button-next",
        prevEl: ".complmntrySwpr .swiper-button-prev",
      },
    });
  }

  if ($(".shwVidoSldr").length) {
    var swiper = new Swiper(".shwVidoSldr .mySwiper", {
      loop: false,
      spaceBetween: 10,
      slidesPerView: "auto",
      grabCursor: false,
      freeMode: true,
      watchSlidesProgress: true,
      noSwipingClass: "vjs-control-bar",
    });
    var swiper2 = new Swiper(".shwVidoSldr .mySwiper2", {
      loop: false,
      spaceBetween: 10,
      grabCursor: false,
      thumbs: {
        swiper: swiper,
      },
      navigation: {
        nextEl: ".shwVidoSldr .swiperBtns .next",
        prevEl: ".shwVidoSldr .swiperBtns .prev",
      },
      noSwipingClass: "vjs-control-bar",
    });
  }

  if ($(".shwImagSldr").length) {
    var swiper = new Swiper(".shwImagSldr .mySwiper", {
      loop: false,
      spaceBetween: 10,
      slidesPerView: "auto",
      freeMode: true,
      watchSlidesProgress: true,
    });
    var swiper2 = new Swiper(".shwImagSldr .mySwiper2", {
      loop: false,
      spaceBetween: 10,
      thumbs: {
        swiper: swiper,
      },
      navigation: {
        nextEl: ".shwImagSldr .swiperBtns .next",
        prevEl: ".shwImagSldr .swiperBtns .prev",
      },
    });
  }

  /********************select-size******************/
  $(".sizeList .form-check").each(function () {
    var thisCheck = $(this);
    thisCheck.find("input").change(function () {
      var labelTxt = $(this).next("label").find("p").text();
      $(".title .selctdSize").text(labelTxt);
    });
  });

  /********************select-color******************/
  $(".colorList .form-check").each(function () {
    var thisCheck = $(this);
    thisCheck.find("input").change(function () {
      var labelTxt = $(this).next("label").find("p").text();
      $(".title .selctdColor").text(labelTxt);
    });
  });

  /********************fltrSubTwo******************/
  if ($(".fltrSubTwo").length) {
    $(".fltrCatLnk").each(function () {
      var thisLnk = $(this);
      thisLnk.click(function () {
        if (!thisLnk.hasClass("open")) {
          $(".fltrCatLnk").removeClass("open");
          $(".fltrSubTwo").slideUp(200);
          thisLnk.addClass("open");
          thisLnk.next(".fltrSubTwo").slideDown(300);
        } else {
          thisLnk.removeClass("open");
          thisLnk.next(".fltrSubTwo").slideUp(300);
        }
      });
    });
  }

  if ($(".fltrTwoLst").length) {
    $(".fltrTwoLnk").each(function () {
      var thisLnk = $(this);
      thisLnk.click(function () {
        if (!thisLnk.hasClass("open")) {
          $(".fltrTwoLnk").removeClass("open");
          $(".fltrTwoLst").slideUp(200);
          thisLnk.addClass("open");
          thisLnk.next(".fltrTwoLst").slideDown(300);
        } else {
          thisLnk.removeClass("open");
          thisLnk.next(".fltrTwoLst").slideUp(300);
        }
      });
    });
  }

  /********************removeAds******************/
  if ($(".removeAds").length) {
    $(".removeAds").click(function () {
      $(".topAdsBx").hide();
      $("body").removeClass("hasTopAds");
    });
  }

  /******************show-link-title*********************/
  if ($(".prdctMenu").length) {
    $(".prdctMenu a").each(function () {
      $(".prdctMenu a").hover(
        function () {
          $(this).find(".linkTitle").fadeIn(400);
        },
        function () {
          $(this).find(".linkTitle").fadeOut(400);
        },
      );
    });
  }

  /******************Rating*********************/
  if ($(".modalRate").length) {
    $(".modalRate").each(function () {
      var thisRating = $(this);

      thisRating.find(".starsLst li").hover(
        function () {
          var onStar = parseInt($(this).data("value"), 10);
          $(this)
            .parent()
            .children("li.star")
            .each(function (e) {
              if (e < onStar) {
                $(this).addClass("hoverStar");
              } else {
                $(this).removeClass("hoverStar");
              }
            });
        },
        function () {
          $(this)
            .parent()
            .children("li.star")
            .each(function (e) {
              $(this).removeClass("hoverStar");
            });
        },
      );

      thisRating.find(".starsLst li").on("click", function () {
        var onStar = parseInt($(this).data("value"), 10);
        var stars = $(this).parent().children("li.star");

        for (i = 0; i < stars.length; i++) {
          $(stars[i]).removeClass("selected");
        }

        for (i = 0; i < onStar; i++) {
          $(stars[i]).addClass("selected");
        }

        var ratingValue = parseInt(
          $(".starsLst li.selected").last().data("value"),
          10,
        );
        var msg = "";
        msg = "<i>" + ratingValue + "</i>" + " / 5";

        thisRating.find("p").html(msg);
      });
    });
  }

  /********************filter-select*********************/
  if ($(".filtrSel").length) {
    $(".filtrSel").each(function () {
      var thisSel = $(this);
      var selTitle = thisSel.find(".fltrSelTtl");
      var selMnu = thisSel.find(".fltrSelMnu");
      selTitle.click(function () {
        if (selTitle.hasClass("open")) {
          selTitle.removeClass("open");
          selMnu.removeClass("open").slideUp(300);
        } else {
          $(this).addClass("open");
          selMnu.addClass("open").slideDown(300);
          thisSel.siblings().find(".fltrSelTtl").removeClass("open");
          thisSel
            .siblings()
            .find(".fltrSelMnu")
            .removeClass("open")
            .slideUp(300);
        }
      });
    });
  }

  /************range-slider*************/
  /* price range*/
  if (document.querySelector(".priceRange")) {
    let priceRange = document.querySelectorAll(".priceRange");
    for (var i = 0; i < priceRange.length; i++) {
      let inputLeft = priceRange[i].querySelector("#input-left");
      let inputRight = priceRange[i].querySelector("#input-right");
      let range = priceRange[i].querySelector(".slider .range");
      let priceFrom = priceRange[i].querySelector(".price-from");
      let priceTo = priceRange[i].querySelector(".price-to");

      function setLeftValue() {
        let _this = inputLeft,
          min = parseInt(_this.min),
          max = parseInt(_this.max);

        _this.value = Math.min(
          parseInt(_this.value),
          parseInt(inputRight.value) - 50,
        );

        let inptMin = `${_this.value}`;
        priceFrom.textContent = delimitNumbers(inptMin);

        let percent = ((_this.value - min) / (max - min)) * 100;

        range.style.left = percent + "%";
      }
      setLeftValue();
      function setRightValue() {
        let _this = inputRight,
          min = parseInt(_this.min),
          max = parseInt(_this.max);

        _this.value = Math.max(
          parseInt(_this.value),
          parseInt(inputLeft.value) + 50,
        );

        let inptMax = `${_this.value}`;
        priceTo.textContent = delimitNumbers(inptMax);

        let percent = ((_this.value - min) / (max - min)) * 100;

        range.style.right = 100 - percent + "%";
      }

      function delimitNumbers(str) {
        return (str + "").replace(/\b(\d+)((\.\d+)*)\b/g, function (a, b, c) {
          return (
            (b.charAt(0) > 0 && !(c || ".").lastIndexOf(".")
              ? b.replace(/(\d)(?=(\d{3})+$)/g, "$1,")
              : b) + c
          );
        });
      }
      setRightValue();
      inputLeft.addEventListener("input", setLeftValue);
      inputRight.addEventListener("input", setRightValue);
      inputLeft.addEventListener("mousedown", (e) => {
        inputLeft.classList.add("active");
      });
      inputLeft.addEventListener("mouseup", (e) => {
        inputLeft.classList.remove("active");
      });

      inputRight.addEventListener("mousedown", (e) => {
        inputRight.classList.add("active");
      });
      inputRight.addEventListener("mouseup", (e) => {
        inputRight.classList.remove("active");
      });
    }
  }

  /*weight range*/
  if (document.querySelector(".weightRng")) {
    let weightRng = document.querySelectorAll(".weightRng");
    for (var i = 0; i < weightRng.length; i++) {
      let inputLeft = weightRng[i].querySelector("#input-left");
      let inputRight = weightRng[i].querySelector("#input-right");
      let range = weightRng[i].querySelector(".slider .range");
      let priceFrom = weightRng[i].querySelector(".price-from");
      let priceTo = weightRng[i].querySelector(".price-to");

      function setLeftValue() {
        let _this = inputLeft,
          min = parseInt(_this.min),
          max = parseInt(_this.max);

        _this.value = Math.min(
          parseInt(_this.value),
          parseInt(inputRight.value),
        );
        priceFrom.textContent = `${_this.value} pt`;

        let percent = ((_this.value - min) / (max - min)) * 100;

        range.style.left = percent + "%";
      }
      setLeftValue();
      function setRightValue() {
        let _this = inputRight,
          min = parseInt(_this.min),
          max = parseInt(_this.max);

        _this.value = Math.max(
          parseInt(_this.value),
          parseInt(inputLeft.value),
        );

        priceTo.textContent = `${_this.value} pt`;

        let percent = ((_this.value - min) / (max - min)) * 100;

        range.style.right = 100 - percent + "%";
      }

      setRightValue();
      inputLeft.addEventListener("input", setLeftValue);
      inputRight.addEventListener("input", setRightValue);
      inputLeft.addEventListener("mousedown", (e) => {
        inputLeft.classList.add("active");
      });
      inputLeft.addEventListener("mouseup", (e) => {
        inputLeft.classList.remove("active");
      });

      inputRight.addEventListener("mousedown", (e) => {
        inputRight.classList.add("active");
      });
      inputRight.addEventListener("mouseup", (e) => {
        inputRight.classList.remove("active");
      });
    }
  }

  /*volume range*/
  if (document.querySelector(".volumeRange")) {
    let volumeRange = document.querySelectorAll(".volumeRange");
    for (var i = 0; i < volumeRange.length; i++) {
      let inputLeft = volumeRange[i].querySelector("#input-left");
      let inputRight = volumeRange[i].querySelector("#input-right");
      let range = volumeRange[i].querySelector(".slider .range");
      let priceFrom = volumeRange[i].querySelector(".price-from");
      let priceTo = volumeRange[i].querySelector(".price-to");

      function setLeftValue() {
        let _this = inputLeft,
          min = parseInt(_this.min),
          max = parseInt(_this.max);

        _this.value = Math.min(
          parseInt(_this.value),
          parseInt(inputRight.value),
        );
        priceFrom.textContent = `${_this.value} ml`;

        let percent = ((_this.value - min) / (max - min)) * 100;

        range.style.left = percent + "%";
      }
      setLeftValue();
      function setRightValue() {
        let _this = inputRight,
          min = parseInt(_this.min),
          max = parseInt(_this.max);

        _this.value = Math.max(
          parseInt(_this.value),
          parseInt(inputLeft.value),
        );

        priceTo.textContent = `${_this.value} ml`;

        let percent = ((_this.value - min) / (max - min)) * 100;

        range.style.right = 100 - percent + "%";
      }

      setRightValue();
      inputLeft.addEventListener("input", setLeftValue);
      inputRight.addEventListener("input", setRightValue);
      inputLeft.addEventListener("mousedown", (e) => {
        inputLeft.classList.add("active");
      });
      inputLeft.addEventListener("mouseup", (e) => {
        inputLeft.classList.remove("active");
      });

      inputRight.addEventListener("mousedown", (e) => {
        inputRight.classList.add("active");
      });
      inputRight.addEventListener("mouseup", (e) => {
        inputRight.classList.remove("active");
      });
    }
  }

  /********************read-more*********************/
  if ($(".hasMore").length) {
    $(".hasMore").each(function () {
      var hasMore = $(this);
      var morLink = hasMore.find(".readMore");
      var morText = hasMore.find(".moreTxt");
      morLink.find("div").click(function (e) {
        e.preventDefault();
        morLink.hide();
        morText.slideDown(500);
      });
    });
  }

  /********************change-icon-color*********************/
  if ($(".sndDateChks").length) {
    $(".sndDateChks").each(function () {
      var thisCheckLst = $(this);
      thisCheckLst.find(".form-check input").change(function () {
        thisCheckLst.parent().find(".sndDateHed span").addClass("blue");
      });
    });
  }

  /********************score-slidr*********************/
  if ($(".scoreSlidr").length) {
    var totalCmnt = $(".scoreSlidr").attr("totalCmnt");
    var scrBx = $(".scoreSlidr").find("li");
    scrBx.each(function () {
      var thisBox = $(this);
      var scrNumber = thisBox.find(".scrSldrBx span").attr("scrNumber");
      var widthPercent = (scrNumber * 100) / totalCmnt;
      var percent = widthPercent + "%";
      thisBox.find(".scrSldrBx span").width(percent);
    });
  }

  /********************rate stars*********************/
  if ($(".prdctRate").length) {
    $(".prdctRate").each(function () {
      var rating = parseFloat($(this).data("rate"));
      $(this)
        .find(".star")
        .each(function (index) {
          if (rating >= index + 1) {
            $(this).addClass("full");
          } else if (rating >= index + 0.5) {
            $(this).addClass("half");
          }
        });
    });
  }

  //new
  /********************show-filter-menu*********************/
  if ($(".opnFltrBtn").length) {
    $(".opnFltrBtn").click(function () {
      $(".resultFltr").addClass("open");
      $("body").addClass("noScroll");
    });

    $(".closFltrBtn").click(function () {
      $(".resultFltr").removeClass("open");
      $("body").removeClass("noScroll");
    });
  }

  if ($(".sortLstBx").length) {
    $(".sortLstHed").click(function () {
      if (!$(".sortLstBx ul").hasClass("open")) {
        $(".sortLstBx ul").addClass("open").slideDown(200);
      } else {
        $(".sortLstBx ul").removeClass("open").slideUp(200);
      }

      $(".sortLstBx input").on("change", function () {
        var thisCheck = $(this);
        if (thisCheck.prop("checked")) {
          var selected = $(this).next("label").text();
          $(".sortLstHed").text(selected);
        }
      });
    });
  }

  /******************count-down*********************/
  if ($(".resendTime").length) {
    $(function () {
      jQuery.fn.extend({
        countdown: function () {
          let min = 3,
            sec = 0;
          render(min, sec);

          const timer = setInterval(() => {
            if (min == 0 && sec == 0) {
              clearInterval(timer);
              return;
            }

            sec = dealSec(sec);
            min = dealMin(min, sec);
            render(min, sec);
          }, 1000);
        },
      });

      $(".resendTime").countdown();
    });

    function dealSec(sec) {
      const timeRange = [...Array(60).keys()].reverse();
      const idxNow = timeRange.indexOf(sec);
      const idxNext = (idxNow + 1) % timeRange.length;
      return timeRange[idxNext];
    }

    function dealMin(min, sec) {
      const timeRange = [...Array(60).keys()].reverse();
      if (sec === 59) {
        const idxNow = timeRange.indexOf(min);
        const idxNext = (idxNow + 1) % timeRange.length;
        return timeRange[idxNext];
      }
      return min;
    }

    function render(min, sec) {
      min = ("00" + min).slice(-2);
      sec = ("00" + sec).slice(-2);

      $(".resendTime span").text(`${min}:${sec}`);
    }
  }

  /**********number-code********************/
  var vcode = (function () {
    var $inputs = $(".verifyCod").find("input");

    $inputs.on("keyup", processInput);

    function processInput(e) {
      var x = e.charCode || e.keyCode;
      if ((x == 8 || x == 46) && this.value.length == 0) {
        var indexNum = $inputs.index(this);
        if (indexNum != 0) {
          $inputs.eq($inputs.index(this) - 1).focus();
        }
      }

      if (ignoreChar(e)) return false;
      else if (this.value.length == this.maxLength) {
        $(this).next("input").focus();
      }
    }
    function ignoreChar(e) {
      var x = e.charCode || e.keyCode;
      if (x == 37 || x == 38 || x == 39 || x == 40) return true;
      else return false;
    }
  })();

  /*************productTab************/
  if ($(".productTab").length) {
    $(window).scroll(function () {
      var position = window.pageYOffset + 132;
      $(".pTabcontent").each(function () {
        var target = $(this).offset().top - 195;
        var id = $(this).attr("id");
        var navLinks = $(".pTabHeader li a");
        if (position >= target) {
          navLinks.removeClass("active");
          $('.pTabHeader li a[href="#' + id + '"]').addClass("active");
        }
      });
    });

    $(".pTablinks").on("click", function () {
      if ($($(this).attr("href")).height() > 400) {
        var half = ($($(this).attr("href")).height() % 2) + 170;
        $("html,body").animate(
          {
            scrollTop: $($(this).attr("href")).offset().top - half,
          },
          300,
        );
      } else if ($($(this).attr("href")).height() < 200) {
        $("html,body").animate(
          {
            scrollTop:
              $($(this).attr("href")).offset().top -
              $($(this).attr("href")).height() -
              130,
          },
          300,
        );
      } else if (
        $($(this).attr("href")).height() > 200 &&
        $($(this).attr("href")).height() < 300
      ) {
        $("html,body").animate(
          {
            scrollTop:
              $($(this).attr("href")).offset().top -
              $($(this).attr("href")).height() +
              50,
          },
          300,
        );
      } else {
        $("html,body").animate(
          {
            scrollTop:
              $($(this).attr("href")).offset().top -
              $($(this).attr("href")).height() +
              140,
          },
          300,
        );
      }
    });
  }

  /*************cmntAddNotf************/
  if ($(".cmntAddNotf").length) {
    $(".cmntAddNotf span").click(function () {
      $(".cmntAddNotf").fadeOut(300);
    });
  }

  /***************item_Num_box**************/
  $(".item_Num_box").each(function () {
    var thisItem = $(this);
    thisItem.find("span").on("click", function () {
      if (thisItem.find("input").val() === "1") {
        thisItem.find(".minus").hide();
        thisItem.find("button").show();
      } else {
        thisItem.find(".minus").show();
        thisItem.find("button").hide();
      }
    });
  });

  /*************hdrPrfilSub************/
  if ($(".hdrPrfilSub").length) {
    $(".hdrPrfiLnk").click(function () {
      $(".hdrPrfiLnk").toggleClass("open");
      $(".hdrPrfilSub").toggleClass("open").slideToggle(300);
    });

    $(".minPrfiLnk").click(function () {
      $(".minPrfilSub").toggleClass("open").slideToggle(300);
    });
  }

  if ($(".fileInput").length) {
    $(".fileInput").change(function () {
      var filename = $(this).val().split("\\").pop();
      $(".selectdFile").html(filename);
    });
  }

  /*************hdrCrtLnk************/
  if ($(window).width() > 767) {
    if ($(".hdrCrtSub").length) {
      $(".hdrCrtBox").hover(
        function () {
          $(".hdrCrtSub").stop(true, true).delay(200).slideDown(300);
        },
        function () {
          $(".hdrCrtSub").stop(true, true).delay(200).slideUp(300);
        },
      );
    }
  }

  /********************Timer*********************/
  if ($(".timeContainer").length) {
    $(".timeContainer").each(function () {
      var thisContaner = $(this);
      const timeEnd = thisContaner.find(".timeEnd").text();
      const __days = thisContaner.find(".wrapper #days");
      const __hours = thisContaner.find(".wrapper #hours");
      const __minutes = thisContaner.find(".wrapper #minutes");
      const __seconds = thisContaner.find(".wrapper #seconds");
      const newYearEnd = timeEnd;
      function countdown() {
        const newYearEndDate = new Date(newYearEnd);
        const currentDate = new Date();

        const totalSeconds = (newYearEndDate - currentDate) / 1000;
        const days = Math.floor(totalSeconds / 3600 / 24);
        const hours = Math.floor(totalSeconds / 3600) % 24;
        const minutes = Math.floor(totalSeconds / 60) % 60;
        const seconds = Math.floor(totalSeconds % 60);

        __days.html(formatTime(days));
        __hours.html(formatTime(hours));
        __minutes.html(formatTime(minutes));
        __seconds.html(formatTime(seconds));
      }
      countdown();
      function formatTime(time) {
        return time < 10 ? `0${time}` : time;
      }
      setInterval(countdown, 1000);
    });
  }

  /********************iframe*********************/
  if ($(".ftrMapIframe").length) {
    $(".ftrMapIframe").attr("src", "");
    var loadSrc = $(".ftrMapIframe").attr("dataSrc");
    $(".ftrMapIframe").attr("src", loadSrc);
  }

  /**************** element transfer ***************/
  let tagName = "transfer";
  let separator = "@";
  $("*[" + tagName + "]").each(function () {
    let element = $(this);
    let prev = element.prev();
    let parent = element.parent();
    let value = element.attr(tagName);
    $(window)
      .resize(function () {
        var size = $(window).width();
        if (value.indexOf(separator) > 0) {
          var slice = value.split(separator);
          var max = parseInt(slice[1]);
          if (size <= max) {
            $(slice[0]).append(element);
          } else {
            if (prev.length > 0) {
              element.insertAfter(prev);
            } else {
              parent.prepend(element);
            }
          }
        } else {
          $(value).append(element);
        }
      })
      .resize();
  });

  //new
  /******************show-footer-menu*******************/
  $(".ftrColTitl").click(function () {
    var thisTitle = $(this);
    if ($(window).width() < 768) {
      thisTitle.toggleClass("active");
      thisTitle.next(".hideCntnt").slideToggle(300);
    }
  });
});

$(window).on("resize", function () {
  var rOffset = $(".hdrTopRow").offset();
  /******************show-footer-menu*******************/
  if ($(window).width() >= 768) {
    $(".ftrColTitl").removeClass("active");
    $(".hideCntnt").show();

    $(".marginRght").css("right", rOffset.left);
  } else {
    $(".ftrColTitl").each(function () {
      var thisTitle = $(this);
      if (!thisTitle.hasClass("active")) {
        thisTitle.next(".hideCntnt").hide();
      }
    });

    $(".marginRght").css("right", "unset");
  }

  /********************changeSrc*********************/
  if ($(".changeSrc").length) {
    $(".changeSrc").each(function () {
      var minSrc = $(this).attr("minSrc");
      var mainSrc = $(this).attr("mainSrc");

      if ($(window).width() < 992) {
        $(this).attr("src", minSrc);
      } else $(this).attr("src", mainSrc);
    });
  }
});

$(window).scroll(function () {
  if (
    $(window).scrollTop() >= 150 &&
    $(window).scrollTop() + $(window).height() != $(document).height() + 20
  ) {
    $(".hdrRowFixd").addClass(
      "fixed , animate__animated , animate__fadeInDown",
    );
  } else {
    $(".hdrRowFixd").removeClass(
      "fixed , animate__animated , animate__fadeInDown",
    );
  }
});
