"use strict";
function getDevice(){
  if(screen.width > 767){
    return "pc";
  }
  return "sp";
}

$(function(){
  var windowObj = $(window);
  /* ページトップ */
  var pagetop = $(".pagetop");
  var windowHeight = windowObj.height();
  var topWindow = windowObj.scrollTop();
  /* スクロール後に表示させる */
  pagetop.hide();
  windowObj.on("scroll", function(){
    if($(this).scrollTop() > 100){
      pagetop.fadeIn("slow");
    }else{
      pagetop.fadeOut("slow");
    }
  });
  /* クリック時スクロールアニメーション */
	pagetop.on("click", function(){
		$("body, html").animate({scrollTop: 0}, 500);
		return false;
	});

  /* スマホ用メニュボタン */
	function toggleNav() {
		var body = document.body;
		var hamburger = document.getElementById('js-hamburger');
		/*var blackBg = document.getElementById('js-black-bg');*/

		hamburger.addEventListener('click', function() {
			body.classList.toggle('nav-open');
		});
		/*blackBg.addEventListener('click', function() {
			body.classList.remove('nav-open');
		});*/
	}
	toggleNav();

  /* #で始まるアンカーをクリックした場合に処理 */
  $('a[href^="#"]').on("click",function(){
    var speed = 1000;
    var href = $(this).attr("href");
    var target = $(href === "" ? "html" : href);
    var position = target.offset().top;
    $("body, html").animate({scrollTop:position}, speed, "swing");
    return false;
  });
});

  /* ヘッダー背景後出し */
$(function() {
  var $win = $(window),
      $header = $('.h_inner'),
      animationClass = 'is-animation';

  $win.on('load scroll', function() {
    var value = $(this).scrollTop();
    if ( value > 300 ) {
      $header.addClass(animationClass);
    } else {
      $header.removeClass(animationClass);
    }
  });
});

function fadeAnime(){
 $('.fadeLeftTrigger').each(function(){ 
    var elemPos = $(this).offset().top-50;
    var scroll = $(window).scrollTop();
    var windowHeight = $(window).height();
    if (scroll >= elemPos - windowHeight){
    $(this).addClass('fadeLeft');
    }else{
    $(this).removeClass('fadeLeft');
    }
    });

  $('.fadeRightTrigger').each(function(){
    var elemPos = $(this).offset().top-50;
    var scroll = $(window).scrollTop();
    var windowHeight = $(window).height();
    if (scroll >= elemPos - windowHeight){
    $(this).addClass('fadeRight');
    }else{
    $(this).removeClass('fadeRight');
    }
    });

 $('.fadeUpTrigger').each(function(){ 
    var elemPos = $(this).offset().top-50;
    var scroll = $(window).scrollTop();
    var windowHeight = $(window).height();
    if (scroll >= elemPos - windowHeight){
    $(this).addClass('fadeUp');
    }else{
    $(this).removeClass('fadeUp');
    }
    });
	
 $('.zoomOutTrigger').each(function(){ 
		var elemPos = $(this).offset().top-50;
		var scroll = $(window).scrollTop();
		var windowHeight = $(window).height();
		if (scroll >= elemPos - windowHeight){
		$(this).addClass('zoomOut');
		}else{
		$(this).removeClass('zoomOut');
		}
	}); 
	
$('.flipRightTrigger').each(function(){
    var elemPos = $(this).offset().top-50;
    var scroll = $(window).scrollTop();
    var windowHeight = $(window).height();
    if (scroll >= elemPos - windowHeight){
    $(this).addClass('flipRight');
    }else{
    $(this).removeClass('flipRight');
    }
    });	
	
$('.flipLeftTrigger').each(function(){
    var elemPos = $(this).offset().top-50;
    var scroll = $(window).scrollTop();
    var windowHeight = $(window).height();
    if (scroll >= elemPos - windowHeight){
    $(this).addClass('flipLeft');
    }else{
    $(this).removeClass('flipLeft');
    }
    });
}
// 画面をスクロールをしたら動かしたい場合の記述
$(window).scroll(function (){
fadeAnime();
});


