// JavaScript Document

$(document).ready(function() {
	"use strict";
	var pagetop = $('.pagetop');
	$(window).scroll(function () {
		if ($(this).scrollTop() > 500) {
			pagetop.fadeIn('slow');
		} else {
			pagetop.fadeOut('slow');
		}
	});
	pagetop.click(function () {
		$('body, html').animate({ scrollTop: 0 }, 750);
		return false;
	});
	$('a[href^=#]').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;
	});
	var pc_width = 736;
	var vp_width = 1200;
	var device = (screen.width < pc_width ? 'sp' : 'pc');
	if (device === 'pc') {
		$("meta[name='viewport']").attr('content', 'width=' + vp_width);
	}
	var toggle = $('#toggle');
	toggle.click(function() {
		$('.gnav').slideToggle(300);
	});
});

$(function() {
	"use strict";
  var $win = $(window),
      $header = $('header'),
      animationClass = 'is-animation';

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

  /* スマホ用メニュボタン */
  $('.toggle').on("click", function(){
    var target_i = $(this);
    var target_gnavArea = $(this).closest('.inner').find(".gnavArea");
    if(target_i.hasClass('fa-bars')){
      target_gnavArea.addClass('is_show');
      target_i.removeClass('fa-bars');
      target_i.addClass('fa-times');
    }else{
      target_gnavArea.removeClass('is_show');
      target_i.removeClass('fa-times');
      target_i.addClass('fa-bars');
    }
  });


//テキストを1文字ずつフェードインさせる
$(function() {
	"use strict";
    var $allMsg = $('.mainTtl');
    var $wordList = $('.mainTtl').html().split("");
    $('.mainTtl').html("");
    $.each($wordList, function(idx, elem) {
        var newEL = $("<span/>").text(elem).css({ opacity: 0 });
        newEL.appendTo($allMsg);
        newEL.delay(idx * 200);
        newEL.animate({ opacity: 1 }, 2200);
    });
});

$(function() {
	"use strict";
    var $allMsg = $('.subTtl');
    var $wordList = $('.subTtl').html().split("");
    $('.subTtl').html("");
    $.each($wordList, function(idx, elem) {
        var newEL = $("<span/>").text(elem).css({ opacity: 0 });
        newEL.appendTo($allMsg);
        newEL.delay(idx * 200);
        newEL.animate({ opacity: 1 }, 1100);
    });
});


//フルスクリーンからのスクロールでコンテンツ表示
var win = $(window);
var win_h = $(window);
//ロード直後
$(document).ready(function () {
	"use strict";
    win_h = win.height();
    $(".mainArea").css("height",win_h + "px");
});
//リサイズ
win.resize(function () {
	"use strict";
	win_h = win.height();
    $(".mainArea").css("height", win_h + "px");
});






if(!navigator.userAgent.match(/(iPhone|iPad|iPod|Android)/)){
	$(function(){
		"use strict";
		$('.fadeInUp').css('visibility','hidden');
		$('.fadeInDown').css('visibility','hidden');
		$('.fadeInRight').css('visibility','hidden');
		$('.fadeInLeft').css('visibility','hidden');
		$(window).scroll(function(){
			var windowHeight = $(window).height(),
				topWindow = $(window).scrollTop();
			$('.fadeInUp').each(function(){
				var targetPosition = $(this).offset().top;
				if(topWindow > targetPosition - windowHeight + 100){
					$(this).addClass("animation_fadeInUp");
				} else {
					$(this).removeClass("animation_fadeInUp");
				}
			});
			$('.fadeInDown').each(function(){
				var targetPosition = $(this).offset().top;
				if(topWindow > targetPosition - windowHeight + 100){
					$(this).addClass("animation_fadeInDown");
				} else {
					$(this).removeClass("animation_fadeInDown");
				}
			});
			$('.fadeInRight').each(function(){
				var targetPosition = $(this).offset().top;
				if(topWindow > targetPosition - windowHeight + 100){
					$(this).addClass("animation_fadeInRight");
				} else {
					$(this).removeClass("animation_fadeInRight");
				}
			});
			$('.fadeInLeft').each(function(){
				var targetPosition = $(this).offset().top;
				if(topWindow > targetPosition - windowHeight + 100){
					$(this).addClass("animation_fadeInLeft");
				} else {
					$(this).removeClass("animation_fadeInLeft");
				}
			});
		});
	});
}






