//////////////////////////////////////////////////////////////////////
// ナビゲーション
//////////////////////////////////////////////////////////////////////
$(".activebtn").click(function () {
  	$(this).toggleClass('open');
  	$(this).toggleClass('act-mix-ex');
    $("#gNav").toggleClass('panelactive');
    $(".extension-bg").toggleClass('extension-active');
});
$("#gNav a").click(function () {
    $(".activebtn").toggleClass('open');
    $(".activebtn").toggleClass('act-mix-ex');
    $("#gNav").toggleClass('panelactive');
    $(".extension-bg").removeClass('extension-active');
});
//////////////////////////////////////////////////////////////////////
// スムーズスクロール
//////////////////////////////////////////////////////////////////////

'use strict';

const links = document.querySelectorAll('a[href^="#"]');

for ( let i = 0; i < links.length; i++ ) {
  links[i].addEventListener('click', (e) => {
    e.preventDefault();

    const href = links[i].getAttribute('href');
    const target = document.getElementById(href.replace('#', ''));
    const rect = target.getBoundingClientRect().top;
    const offset = window.pageYOffset;
	const gap = 0; // 固定ヘッダー分の高さ
    const position = rect + offset - gap;
    window.scroll({
      top: position,
      behavior: 'smooth'
    });
  });
}

//////////////////////////////////////////////////////////////////////
//タブ
//////////////////////////////////////////////////////////////////////

function GethashID (hashIDName){
	if(hashIDName){
		$('.tab li').find('a').each(function() {
			var idName = $(this).attr('href'); 	
			if(idName == hashIDName){ 
				var parentElm = $(this).parent(); 
				$('.tab li').removeClass("active"); 
				$(parentElm).addClass("active"); 
				$(".area").removeClass("is-active"); 
				$(hashIDName).addClass("is-active"); 	
			}
		});
	}
}

$('.tab a').on('click', function() {
	var idName = $(this).attr('href'); 
	GethashID (idName);
	return false;
});


$(window).on('load', function () {
    $('.tab li:nth-of-type(2)').addClass("active");
    $('.area:nth-of-type(2)').addClass("is-active");
	var hashName = location.hash;
	GethashID (hashName);
});

///////////////////////////////////////////////////////////////////////
//fadeinout
///////////////////////////////////////////////////////////////////////
$(function(){
 
  $(window).on('load scroll', function(){
    //現時点のスクロールの高さ取得
    var scrollPosition = $(window).scrollTop();
    //ウィンドウの高さ取得
    var windowHeight = $(window).height();
 
    $('.animation_box').each(function(){
      //要素の位置（高さ）を取得
      var elemPosition = $(this).offset().top;
      //スクロールの高さが要素の位置を超えたら以下のスタイルを適用
      if(elemPosition < scrollPosition + windowHeight){
        $(this).css({
          opacity: 1,
          transform: 'translateY(0)'
        });
      }
    });
  });
});
///////////////////////////////////////////////////////////////////////
//遷移後スクロール
///////////////////////////////////////////////////////////////////////
$(function(){
	//現在のページURLのハッシュ部分を取得
	const hash = location.hash;

	//ハッシュ部分がある場合の条件分岐
	if(hash){
		//ページ遷移後のスクロール位置指定
		$("html, body").stop().scrollTop(0);
		//処理を遅らせる
		setTimeout(function(){
			//リンク先を取得
			const target = $(hash),
			//リンク先までの距離を取得
			position = target.offset().top;
			//指定の場所までスムーススクロール
			$("html, body").animate({scrollTop:position}, 500, "swing");
		});
	}
});
//////////////////////////////////////////////////////////////////////
//ナビゲーションホバーアコーディング
//////////////////////////////////////////////////////////////////////

$('.gnav__list>li').find('ul').hide();
$('.gnav__list>li').hover(function(){
  $(this).children('.sub-menu').stop().slideDown(500);
},function(){
  $(this).children('.sub-menu').stop().slideUp(500);
});

///////////////////////////////////////////////////////////////
//スライドショー
///////////////////////////////////////////////////////////////
$(document).ready(function() {
    $('.slides').slick({
 		autoplay: true,
		arrows:false,
    dots: false,
    infinite: true,
    pauseOnHover: false,
    slidesToShow:4,
		centerMode:true,
    centerPadding: 'calc((100% - 960px) / 2 - 50px)',
		responsive: [
	  {
		breakpoint: 1000,
      settings: {
    centerPadding: 'calc((100% - 700px) / 2 - 50px)',
    slidesToShow:3,
      }},
	  {
		breakpoint: 768,
      settings: {
    centerPadding: 'calc((100% - 400px) / 2 - 50px)',
    slidesToShow:2,
      }},
	  {
      breakpoint: 610,
      settings: {
    centerPadding: 'calc((100% - 150px) / 2 - 50px)',
      slidesToShow:1,
      }
    }
  ]
    });
});
//////////////////////////////////////////////////////////////////////
//luxy
//////////////////////////////////////////////////////////////////////

if (navigator.userAgent.indexOf('iPhone') > 0 || navigator.userAgent.indexOf('Android') > 0 && navigator.userAgent.indexOf('Mobile') > 0) {
    // スマートフォン向けの記述
} else if (navigator.userAgent.indexOf('iPad') > 0 || navigator.userAgent.indexOf('Android') > 0) {
    // タブレット向けの記述
} else {
    // PC向けの記述
    luxy.init();
}