// $(window).on("load", function(){
//   $(".loading").fadeOut();
// });

$(function(){
  setTimeout(function(){
    $(".loading").fadeOut();
  },1000);
});
//ドロワー
$(function(){
  $("#nav-toggle").on("click", function(){
    $("body").toggleClass("open");
  });
  $(".close-btn , .access a").on("click", function(){
    $("body").removeClass("open");
  });
});

//スクロール系
$(function(){
  var hs = $("header");
  var spf = $(".sp-foot");
  $(window).scroll(function () {
    if ( $(this).scrollTop() > 100 ) {
      hs.addClass("header-bg");
      spf.addClass("fixed-foot");
    } else {
      hs.removeClass("header-bg");
      spf.removeClass("fixed-foot");
    }
  });
});

//アコーディオンFAQ
$(function(){
	$(".accordion li div").on("click", function() {
		$(this).next().slideToggle();
		if ($(this).children(".accordion_icon").hasClass('active')) {
			$(this).children(".accordion_icon").removeClass('active');
		}
		else {
			$(this).children(".accordion_icon").addClass('active');
		}
	});
});

//スムーススクロール
$(function(){
  $('a[href^="#"]').click(function(){
    var speed = 500;
    var href = $(this).attr("href");
    var target = $(href == "#" || href == "" ? 'html' : href);
    var header = $('header').height();
    var position = target.offset().top - header;
    $("html, body").animate({scrollTop:position}, speed, "swing");
    return false;
  });
});

//バリデート
$(function() {
    $("#mail").on("keyup change", function() {
        if ($(this).val() != $('#mail2').val()) {
            $("#agreement").prop("disabled", true);
            $('#err').show();
        } else {
            $("#agreement").prop("disabled", false);
            $('#err').hide();
        }
    });
    $("#mail2").on("keyup change", function() {
        if ($(this).val() != $('#mail').val()) {
            $("#agreement").prop("disabled", true);
            $('#err').show();
        } else {
            $("#agreement").prop("disabled", false);
            $('#err').hide();
        }
    });
    $(".reserve #submit").on("click", function() {
      if ($('.reserve #schedule').val().length < 1) {
        $("#agree").prop("disabled", true);
        $('#schedule_err').show();
        return false;
      }
    });
});

$(function() {
    $("#submit").prop("disabled", true);

    $("#agreement").on("click", function() {
        if ($(this).prop("checked") == false) {
            $("#submit").prop("disabled", true);
        } else {
            $("#submit").prop("disabled", false);
        }
    });
});

//Modal Window
$(function(){
  var winScrollTop;
  $(".js-modal-open").each(function(){
    $(this).on('click',function(){
      //スクロール位置を取得
      winScrollTop = $(window).scrollTop();
      var target = $(this).data("target");
      var modal = document.getElementById(target);
      $(modal).fadeIn();
      return false;
    });
  });
  $(".js-modal-close").on("click",function(){
    $(".js-modal").fadeOut();
    $("body,html").stop().animate({scrollTop:winScrollTop}, 100);
    return false;
  });
});

$(function(){
  $('#staff-order').on('change',function(){
    $('#staff-search').submit();
  });
});

//WOW
$(function() {
	new WOW().init();
});

//ルーム分け
$(function(){
  $(".main-tab").on("click",function(){
  	var $th = $(this).index();
  	$(".main-tab").removeClass("active");
  	$("#main-panel .main-tab-panel").removeClass("active");
  	$(this).addClass("active");
  	$("#main-panel .main-tab-panel").eq($th).addClass("active");
  });
});

//ぱんくず調整
$(function(){
  var last_li = $('.breadcrumb ol li:last');
  console.log(last_li.html());
  if (!$('.breadcrumb').html()){
    return;
  }
  var a = last_li.children('a').html();

  last_li.children('a').remove().html();
  var meta = last_li.html();

  last_li.html(meta + a);
});

//レビュー機能
function post_review() {
  $(function(){
    $('#btn-review').on('click',function(){
      $(this).next().slideToggle();
    });
  });

  $(function(){
    $('#rev-submit span').on('click',function(){
      if(!confirm('この内容で送信します。\nよろしいですか？')) {
        return false;
      } else {
        var staff = $(this).data('stf'),
            name = $('#namae').val(),
            udat = $('#schedule').val(),
            eval = $('#eval').val(),
            msg = $('#msg').val(),
            token = $(this).data('token');
        if (!name || !udat || !eval || !msg) {
          alert('未入力箇所があります。');
          return false;
        } else {
          $.ajax({
            url:'/set_review.php',
            type:'post',
            data:{
              'staff':staff,
              'name':name,
              'udat':udat,
              'eval':eval,
              'msg':msg,
              'token':token
            },
            timeout:10000,
          }).done((data) => {
            alert('送信しました。');
            location.reload();
          }).fail((data) => {
            console.log(data);
          });
        }
      }
    });
  });
}
post_review();

/***************************************************************************
*
*	追記
*
***************************************************************************/
function profSlider(){
  // alert();
let profSlider = new Swiper('#profSlider', {
  loop: true,
  speed: 1500,
  slidesPerView: 1,
  centeredSlides: true,
  loopedSlides: 3,
});

let thumbnail = new Swiper('#thumbSlider', {
  loop: true,
  slidesPerView: 3,
  slideToClickedSlide: true,
  centeredSlides: true,
  spaceBetween: 8,
});
profSlider.controller.control = thumbnail;
thumbnail.controller.control = profSlider;
}
