
jQuery(function ($) { // この中であればWordpressでも「$」が使用可能になる

  var topBtn = $('.pagetop');
  topBtn.hide();

  // ボタンの表示設定
  $(window).scroll(function () {
    if ($(this).scrollTop() > 70) {
      // 指定px以上のスクロールでボタンを表示
      topBtn.fadeIn();
    } else {
      // 画面が指定pxより上ならボタンを非表示
      topBtn.fadeOut();
    }
  });

  // ボタンをクリックしたらスクロールして上に戻る
  topBtn.click(function () {
    $('body,html').animate({
      scrollTop: 0
    }, 300, 'swing');
    return false;
  });

  //ドロワーメニュー
  $("#MenuButton").click(function () {
    // $(".l-drawer-menu").toggleClass("is-show");
    // $(".p-drawer-menu").toggleClass("is-show");
    $(".js-drawer-open").toggleClass("open");
    $(".drawer-menu").toggleClass("open");
    $("html").toggleClass("is-fixed");
  });

  $('.js-hamburger').on('click', function () {
    if ($('.js-hamburger').hasClass('open')) {
      $('.js-drawer-menu').fadeOut();
      $('body').removeClass('fixed');
      $('.js-hamburger span').removeClass('color');
      $('.hamburgerColor').removeClass('color');
      $('.p-header__title').removeClass('none');
      $(this).removeClass('open');
    } else {
      $('.js-drawer-menu').fadeIn();
      $('body').addClass('fixed');
      $('.js-hamburger span').addClass('color');
      $('.hamburgerColor').addClass('color');
      $('.p-header__title').addClass('none');
      $(this).addClass('open');
    }
  });
  
  //ポイントに要素追加
  $('.p-point__lists .p-point__list:nth-child(1)').find('.p-point__img').addClass('js-fadeIn');
  $('.p-point__lists .p-point__list:nth-child(2)').find('.p-point__img').addClass('js-fadeIn');
  $('.p-point__lists .p-point__list:nth-child(3)').find('.p-point__img').addClass('js-fadeIn');

  // チェックボックスのテキストを消す
  $('.wpcf7-list-item-label').empty();
});


//ドロワーメニューをクリックしたらメニューを閉じる
$(function () {
  $('.p-drawer-menu__list>a, .u-contact').click(function () {
    $('.js-drawer-menu').fadeOut();
    $('.js-hamburger').removeClass('open');
    $('body').removeClass('fixed');
  });
});


//fade inアニメーション
$(function () {
  $(window).on('load scroll', function () {
    $('.js-fadeIn').each(function () {
      //ターゲットの位置を取得
      var target = $(this).offset().top;
      //スクロール量を取得
      var scroll = $(window).scrollTop();
      //ウィンドウの高さを取得
      var height = $(window).height();
      //ターゲットまでスクロールするとフェードインする
      if (scroll > target - height) {
        //クラスを付与
        $(this).addClass('u-active');
      }
    });
    $('.js-fadeIn-right').each(function () {
      //ターゲットの位置を取得
      var target = $(this).offset().top;
      //スクロール量を取得
      var scroll = $(window).scrollTop();
      //ウィンドウの高さを取得
      var height = $(window).height();
      //ターゲットまでスクロールするとフェードインする
      if (scroll > target - height) {
        //クラスを付与
        $(this).addClass('u-active-right');
      }
    });
    $('.js-fadeIn-left').each(function () {
      //ターゲットの位置を取得
      var target = $(this).offset().top;
      //スクロール量を取得
      var scroll = $(window).scrollTop();
      //ウィンドウの高さを取得
      var height = $(window).height();
      //ターゲットまでスクロールするとフェードインする
      if (scroll > target - height) {
        //クラスを付与
        $(this).addClass('u-active-left');
      }
    });
  });
});


// ローディング画面
$(function () {
  var webStorage = function () {
    if (sessionStorage.getItem("access")) {
      /*2回目以降アクセス時の処理*/
      $(".shutter").addClass('is-active');
    } else {
      /*初回アクセス時の処理*/
      sessionStorage.setItem('access', 'true'); // sessionStorageにデータを保存
      // loadingアニメーションを表示
      setTimeout(function () {
        // ローディングを数秒後に非表示にする
        $(".shutter").removeClass('is-active');
      },); // ローディングを表示する時間
    }
  }
  webStorage();
});

//固定ヘッダーの指定
const headerHeight = $('header').outerHeight();
// ページ外アンカーのページ付きリンクへのスムーススクロール
var urlHash = location.hash;
if (urlHash) {
  $('body,html').stop().scrollTop(0);
  setTimeout(function () {
    var target = $(urlHash);
    var position = target.offset().top - headerHeight;
    $('body,html').stop().animate({ scrollTop: position }, 500);
  }, 100);
}
// ページ内アンカーのページ付きリンクへのスムーススクロール
$(function () {
  $('a[href*="#"], area[href*="#"]').not(".noScroll").click(function () {
    var speed = 400, // ミリ秒(この値を変えるとスピードが変わる)
      href = $(this).prop("href"), //リンク先を絶対パスとして取得
      hrefPageUrl = href.split("#")[0], //リンク先を絶対パスについて、#より前のURLを取得
      currentUrl = location.href, //現在のページの絶対パスを取得
      currentUrl = currentUrl.split("#")[0]; //現在のページの絶対パスについて、#より前のURLを取得
    //#より前の絶対パスが、リンク先と現在のページで同じだったらスムーススクロールを実行
    if (hrefPageUrl == currentUrl) {
      //リンク先の#からあとの値を取得
      href = href.split("#");
      href = href.pop();
      href = "#" + href;
      //スムースクロールの実装
      var target = $(href == "#" || href == "" ? 'html' : href),
        position = target.offset().top - headerHeight; //targetの位置を取得
      $('body,html').stop().animate({ scrollTop: position }, 500);
      return false;
    }
  });
});