//スクロールトップ
var windowWidth = $(window).width();
var windowSm = 768;
if (windowWidth <= windowSm) {
  $(document).ready(function () {
    $("#topBtn").hide();
    $(window).on("scroll", function () {
      if ($(this).scrollTop() > 100) {
        $("#topBtn").fadeIn("fast");
      } else {
        $("#topBtn").fadeOut("fast");
      }
      scrollHeight = $(document).height(); //ドキュメントの高さ
      scrollPosition = $(window).height() + $(window).scrollTop(); //現在地
      footHeight = $("footer").innerHeight(); //footerの高さ（＝止めたい位置）
      if (scrollHeight - scrollPosition <= footHeight) {
        //ドキュメントの高さと現在地の差がfooterの高さ以下になったら
        $("#topBtn").css({
          position: "absolute", //pisitionをabsolute（親：wrapperからの絶対値）に変更
          bottom: footHeight - 30, //下からfooterの高さ + 20px上げた位置に配置
        });
      } else {
        //それ以外の場合は
        $("#topBtn").css({
          position: "fixed", //固定表示
          bottom: "91px", //下から20px上げた位置に
        });
      }
    });
  });
} else {
  $(document).ready(function () {
    $("#topBtn").hide();
    $(window).on("scroll", function () {
      if ($(this).scrollTop() > 100) {
        $("#topBtn").fadeIn("fast");
      } else {
        $("#topBtn").fadeOut("fast");
      }
      scrollHeight = $(document).height(); //ドキュメントの高さ
      scrollPosition = $(window).height() + $(window).scrollTop(); //現在地
      footHeight = $("footer").innerHeight(); //footerの高さ（＝止めたい位置）
      if (scrollHeight - scrollPosition <= footHeight) {
        //ドキュメントの高さと現在地の差がfooterの高さ以下になったら
        $("#topBtn").css({
          position: "absolute", //pisitionをabsolute（親：wrapperからの絶対値）に変更
          bottom: footHeight + 20, //下からfooterの高さ + 20px上げた位置に配置
        });
      } else {
        //それ以外の場合は
        $("#topBtn").css({
          position: "fixed", //固定表示
          bottom: "91px", //下から20px上げた位置に
        });
      }
    });
    $("#topBtn").click(function () {
      $("body,html").animate(
        {
          scrollTop: 0,
        },
        400
      );
      return false;
    });
  });
}

$(function () {
  var windowWidth = $(window).width();
  var windowSm = 768;
  if (windowWidth >= windowSm) {
    //pc以上
    $(".js-video-switch").on("click", function () {
      $(".modal-video").addClass("show"); //モーダル表示
      $(".pc-video").get(0).play(); //動画再生。get(0)を書かないとjQueryは動かないです
    });
    $(".close-btn").on("click", function () {
      $(".modal-video").removeClass("show"); //モーダル非表示
      $(".pc-video").get(0).pause(); //動画一時停止。これもget(0)ほしいです
    });
  } else {
    //スマホのときは勝手にモーダル出してくれるのでオフにします
  }
});

//ローディング
$(window).on("load", function () {
  // $('html,body').animate({ scrollTop: 0 }, '1');
  $("#loading").addClass("out");
  $("#loading .load_move").addClass("in");
  $("#wrapper").removeClass("hidden");
  setTimeout(function () {
    //～ローディングから.6秒後～
    $("#loading").addClass("none");
  }, 2000);

  /* setTimeout(function () {
    //～ローディングから.6秒後～
    $(".fv_move_01").addClass("active");
  }, 2600);
  setTimeout(function () {
    $(".fv_move_02").addClass("active");
  }, 3100);
  setTimeout(function () {
    $(".fv_move_03").addClass("active");
  }, 3400);
  setTimeout(function () {
    $(".fv_move_04").addClass("active");
  }, 3600);
  setTimeout(function () {
    $(".area_ttl").addClass("finish");
  }, 4000);
  setTimeout(function () {
    $(".area_ttl").removeClass("scale_9");
  }, 4000);
  setTimeout(function () {
    $(".area_ttl").addClass("endscale");
  }, 4800);
  setTimeout(function () {
    $(".area_arrow").addClass("show");
  }, 5000); */

  ////sp_FV////
  /* setTimeout(function () {
    //～ローディングから.6秒後sp～
    $(".fv_move_01").addClass("active");
  }, 2600);
  setTimeout(function () {
    $(".fv_move_02").addClass("active");
  }, 3100);
  setTimeout(function () {
    $(".fv_move_03").addClass("active");
  }, 3400);
  setTimeout(function () {
    $("fv_move_04").addClass("active");
  }, 3600);
  setTimeout(function () {
    $(".sparea_ttl").addClass("finish");
  }, 4000);
  setTimeout(function () {
    $(".sparea_ttl").addClass("endscale");
  }, 4800);
  setTimeout(function () {
    $(".sparea_arrow").addClass("show");
  }, 5000); */
});

//drawer
$(document).ready(function () {
  $(".drawer").drawer({
    class: {
      nav: "drawer-nav",
      toggle: "drawer-toggle",
      overlay: "drawer-overlay",
      open: "drawer-open",
      close: "drawer-close",
      dropdown: "drawer-dropdown",
    },
    iscroll: {
      // Configuring the iScroll
      // https://github.com/cubiq/iscroll#configuring-the-iscroll
      mouseWheel: true,
      preventDefault: false,
    },
    showOverlay: true,
  });
  $(".drawer-dropdown").on("click", function () {
    $(this).toggleClass("open");
    // $(this).children($(".drawer-menu-item")).attr(); //モーダル表示
  });
});
