(function ($) {
  "use strict";

  /* ----------------------------------------------------------- */
  /*  Back to top
		/* ----------------------------------------------------------- */

  $(window).scroll(function () {
    if ($(this).scrollTop() > 300) {
      $(".backto").fadeIn();
    } else {
      $(".backto").fadeOut();
    }
  });

  // scroll body to 0px on click
  $(".backto").on("click", function () {
    $(".backto").tooltip("hide");
    $("body,html").animate(
      {
        scrollTop: 0,
      },
      800
    );
    return false;
  });

  $(".backto").tooltip("hide");

  //Hide Loading Box (Preloader)
  function handlePreloader() {
    if ($(".theme-loader-wrap").length) {
      $(".theme-loader-wrap").delay(1000).fadeOut(500);
    }
  }

  if ($(".preloader-close").length) {
    $(".preloader-close").on("click", function () {
      $(".theme-loader-wrap").delay(200).fadeOut(500);
    });
  }

  /* ==========================================================================
		When document is loaded, do
		========================================================================== */

  $(window).on("load", function () {
    handlePreloader();
  });

  jQuery(".mainmenu ul.theme-main-menu").slicknav({
    allowParentLinks: true,
    prependTo: ".meditest-responsive-menu",
    closedSymbol: "&#8594",
    openedSymbol: "&#8595",
  });

  /* ----------------------------------------------------------- */
  /*  Video popup
	   /* ----------------------------------------------------------- */

  if ($(".video-play-btn").length > 0) {
    $(".video-play-btn").magnificPopup({
      type: "iframe",
      mainClass: "mfp-with-zoom",
      zoom: {
        enabled: true, // By default it's false, so don't forget to enable it

        duration: 300, // duration of the effect, in milliseconds
        easing: "ease-in-out", // CSS transition easing function

        opener: function (openerElement) {
          return openerElement.is("img")
            ? openerElement
            : openerElement.find("img");
        },
      },
    });
  }

  /* ----------------------------------------------------------- */
  /*  Sticky Header
	/* ----------------------------------------------------------- */

  $(window).on("scroll", function (event) {
    var scroll = $(window).scrollTop();
    if (scroll < 86) {
      $(".stick-top").removeClass("sticky");
    } else {
      $(".stick-top").addClass("sticky");
    }
  });
})(jQuery);
