///////////////////////////////////////////////////////////////////////
//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)'
        });
      }
    });
  });
});

//////////////////////////////////////////////////////////////////////
// ナビゲーション
//////////////////////////////////////////////////////////////////////
$(".activebtn").click(function () {
  	$(this).toggleClass('open');
  	$(this).toggleClass('act-mix-ex');
    $("#gNav").toggleClass('panelactive');
    $("#banner").toggleClass('bannerdelete');
    $(".extension-bg").toggleClass('extension-active');
});
$("#gNav a").click(function () {
    $(".activebtn").toggleClass('open');
    $(".activebtn").toggleClass('act-mix-ex');
    $("#gNav").toggleClass('panelactive');
    $("#banner").toggleClass('bannerdelete');
    $(".extension-bg").removeClass('extension-active');
});

///////////////////////////////////////////////////////////////////////
//遷移後スクロール
///////////////////////////////////////////////////////////////////////
$(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");
		});
	}
});

///////////////////////////////////////////////////////////////
//スライドショー
///////////////////////////////////////////////////////////////
$(document).ready(function() {
    $('.slides').slick({
 		autoplay: true,
		arrows:false,
    dots: false,
    infinite: true,
    pauseOnHover: false,
    slidesToShow:2,
		centerMode:true,
    centerPadding: 'calc((100% - 640px) / 2 - 50px)',
		responsive: [
	  {
		breakpoint: 930,
      settings: {
    centerPadding: 'calc((100% - 270px) / 2 - 50px)',
    slidesToShow:1,
      }},
	  {
      breakpoint: 480,
      settings: {
    centerPadding: 'calc((100% - 270px) / 2 - 50px)',
      slidesToShow:2,
      }
    },
	  {
      breakpoint: 390,
      settings: {
    centerPadding: 'calc((100% - 85px) / 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();
}

// aタグのクリックイベントを取得
const anchorLinks = document.querySelectorAll('a[href^="#"]');

anchorLinks.forEach(link => {
  link.addEventListener('click', (e) => {
    e.preventDefault(); // 通常の移動をキャンセル

    const targetId = link.getAttribute('href'); // #section1 など
    const targetElement = document.querySelector(targetId);
    
    if (targetElement) {
      // ターゲット要素の位置を取得
      const targetPosition = targetElement.getBoundingClientRect().top;
      
      // luxyWrapper (通常は#luxy) を取得し、そこからの相対位置で計算
      const currentScroll = window.pageYOffset || document.documentElement.scrollTop;
      const offsetPosition = targetPosition + currentScroll;

      // Luxyの内部値（スクロール位置）を移動させる
      // ※注意：luxy.jsのバージョンやラッパー設定により調整が必要
      window.scrollTo({
        top: offsetPosition,
        behavior: 'smooth' // ブラウザ標準のスムーススクロールを使う場合
      });
    }
  });
});