$(document).ready(function () {
  window.addEventListener("contextmenu", (event) => {
    event.preventDefault();
  });
  var showPopup = false;
  var hidePopup = true;
  var showPlay = true;
  document.getElementById("play").addEventListener("click", () => {
    window.scrollTo(0, 0);
    $("#play").fadeOut("fast", function () {
      $("#video").prop("muted", false).prop("currentTime", 0).trigger("play");
      $("#container_video").addClass("fullscreen");
      $("body").addClass("noscroll");
      $("#close").fadeIn();
      showPlay = false;
    });
  });
  document.getElementById("open-video").addEventListener("click", () => {
    window.scrollTo(0, 0);
    $("#open-video").fadeOut("fast", function () {
      $("#container_video").addClass("fullscreen");
      $("body").addClass("noscroll");
      $("#close").fadeIn();
      showPlay = false;
    });
  });
  $(document).bind("contextmenu", function (e) {
    e.preventDefault();
  });
  $(document).keydown(function (e) {
    if (e.which === 123) {
      return false;
    }
  });
  document.onkeydown = function (e) {
    if (event.keyCode == 123) {
      return false;
    }
    if (
      e.ctrlKey &&
      e.shiftKey &&
      (e.keyCode == "I".charCodeAt(0) || e.keyCode == "i".charCodeAt(0))
    ) {
      return false;
    }
    if (
      e.ctrlKey &&
      e.shiftKey &&
      (e.keyCode == "C".charCodeAt(0) || e.keyCode == "c".charCodeAt(0))
    ) {
      return false;
    }
    if (
      e.ctrlKey &&
      e.shiftKey &&
      (e.keyCode == "J".charCodeAt(0) || e.keyCode == "j".charCodeAt(0))
    ) {
      return false;
    }
    if (
      e.ctrlKey &&
      (e.keyCode == "U".charCodeAt(0) || e.keyCode == "u".charCodeAt(0))
    ) {
      return false;
    }
    if (
      e.ctrlKey &&
      (e.keyCode == "S".charCodeAt(0) || e.keyCode == "s".charCodeAt(0))
    ) {
      return false;
    }
  };
  $("#video")
    .on("timeupdate", function () {
      if (!showPlay && !showPopup && $(this).prop("currentTime") > start) {
        $("#popup").fadeIn("fast");
        showPopup = true;
      }
      if (hidePopup && $(this).prop("currentTime") > start + duration) {
        $("#popup").fadeOut("fast");
        hidePopup = false;
      }
    })
    .on("ended", showOrder);
  $("#popup").on("click", showOrder);
  $("#close").on("click", function () {
    $(this).hide();
    $("#container_video").removeClass("fullscreen");
    $("body").removeClass("noscroll");
    $("#open-video").fadeIn("fast");
    $("#popup").fadeOut("fast");
  });
  function showOrder() {
    $("#container_video").removeClass("fullscreen");
    $("body").removeClass("noscroll");
    $("#popup").fadeOut();
    $("#close").fadeOut();
    $("#video").fadeOut("fast", function () {
      $(this).trigger("pause");
      $("#order").fadeIn("fast", function () {
        $("html, body").animate(
          { scrollTop: $("#order").offset().top - 20 },
          200,
        );
      });
    });
  }
});
