var userAgent = window.navigator.userAgent.toLowerCase();

$(function () {
	
	

	 
	 
if( userAgent.match(/(msie|MSIE)/) || userAgent.match(/(T|t)rident/) ) {
    var b_isIE = true;
    var ieVersion = userAgent.match(/((msie|MSIE)\s|rv:)([\d\.]+)/)[3];
    ieVersion = parseInt(ieVersion);
    $('html').addClass('IE version_'+ ieVersion)
    
} else {
    var b_isIE = false;
  }

});


var vh = window.innerHeight * 0.01;
document.documentElement.style.setProperty('--vh', vh+'px');

window.addEventListener( 'resize', function() {
  var vh = window.innerHeight * 0.01;
  document.documentElement.style.setProperty('--vh', vh+'px');
}, false );



window.onpageshow = function(event) {
	if (event.persisted) {
		 window.location.reload();
	}
};

//debug mode
var debugMode = false;
var debugGA = false;
var consoleMode = false;


//page id
var page_id;

//loading
var loadEndFlag = false;

//window size
var winHeight = window.innerHeight;
var winWidth = window.innerWidth;

// Default global var
var ua;
var isOS;
var isDevice;
var clickevent;
var isSize;
var isMini;
var isTouchDevice = false;

//Device
var ua = navigator.userAgent.toLowerCase();
var isWindows = /windows/.test(ua);
var isMac = /mac/.test(ua);
var isIPhone = /i(phone|pod)/.test(ua);
var isIPad = /ipad/.test(ua);
var isIOS = isIPhone || isIPad;
var isAndroid = /android/.test(ua);
var isAndroidMobile = /android(.+)?mobile/.test(ua);
var isIE = /msie/.test(ua);
var isFirefox = /firefox/.test(ua);
var isChrome = /chrome/.test(ua);
var isCrios = /crios/.test(ua);
var isSafari = /safari/.test(ua);
var isOpera = /opera/.test(ua);
var isOperaMobile = /opera mobi/.test(ua);
var isOperaMini = /opera mini/.test(ua);
var isSmartphone = isIPhone || isAndroidMobile;
var isPC = !isIOS && !isAndroid;
var chkTouch = ('ontouchstart' in window);
var isTablet;

var ua2 = navigator.userAgent;
if (ua2.indexOf('iPhone') > 0 || ua2.indexOf('iPod') > 0 || ua2.indexOf('Android') > 0 && ua2.indexOf('Mobile') > 0) {
	if (consoleMode) {console.log('smart phone');}
    var viewMode = true;
} else if (ua2.indexOf('iPad') > 0 || ua2.indexOf('Android') > 0) {
	if (consoleMode) {console.log('ipad');}
    var viewMode = true;
} else if (isSafari && typeof document.ontouchstart !== 'undefined') {
	if (consoleMode) {console.log('ipadOS tablet');}
    var viewMode = true;
     isTablet = true;
} else {
	if (consoleMode) {console.log('pc');}
    var viewMode = false;
}



if ((ua2.indexOf('Android') > 0 && ua2.indexOf('Mobile') == -1) || ua2.indexOf('iPad') > 0 || ua2.indexOf('Kindle') > 0 || ua2.indexOf('Silk') > 0) {
    isTablet = true;
}


if (isSmartphone) {
    isDevice = "sp";
    isTouchDevice = true;
} else if (isIOS) {
    isDevice = "ios";
    isTouchDevice = true;
} else {
    isDevice = "pc";
}

//os
if (isIOS) {
    isOS = "ios";
} else if (isAndroid) {
    isOS = "android";
} else if (isMac) {
    isOS = "mac";
} else if (isWindows) {
    isOS = "windows";
}









/**
* global var
*/

var global_title_target = 'TOP';
var global_scroll_direction = false;
var global_scroll_pos = 0;

var global_menu_flag = false;


/**
* ピンチを制御
*/
function no_scaling() {
    document.addEventListener("touchmove", mobile_no_scroll, { passive: false });
}
/**
* タッチ操作での拡大縮小禁止解除
*/
function return_scaling() {
    document.removeEventListener('touchmove', mobile_no_scroll, { passive: false });
}
/**
* 拡大縮小禁止
*/
function mobile_no_scroll(event) {
    // ２本指での操作の場合
    if (event.touches.length >= 2) {
        // デフォルトの動作をさせない
        event.preventDefault();
    }
}
//no_scaling();


function Fn_gaEvent(params_1 , params_2 , params_3) {
		if(debugGA){ console.log(' ga send = event , params:[ '+ params_1 + ' , '+ params_2 + ' , '+ params_3 + ']');}
		gtag('event',params_2, {'event_category':params_1,'event_label': params_3});
}




$.fn.initvar = function (flag) {
    if (isSmartphone) {
        $("html").addClass('touchDevice');
        $("html").removeClass('pcDevice');
    } else {
        $("html").addClass('pcDevice');
        $("html").removeClass('touchDevice');
    }
    if (isSmartphone) {
        $("html").addClass('smartPhone');
    }
    if (isIPad) {
        $("html").addClass('iPad');
    }

    if (isTablet) {
        $("html").addClass('isTablet');
    }
}


function pageMove(url){
	     $('body').prepend('<div id="loader" class="gh move"><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"></div><div class="line"></div></div>');

        setTimeout(function () {
            $('#loader').addClass('in');
        }, 100)
        setTimeout(function () {
            location.href = url;
        }, 1500)

}


function Fn_pageScroll(target,scroll_speed,offset){
		

        if(target){
            //ページ遷移後のスクロール位置指定
            $("html, body").stop().scrollTop(0);
            //処理を遅らせる
      
                //リンク先を取得
              
                //リンク先までの距離を取得
                position = $('#parking').offset().top;
                //指定の場所までスムーススクロール
                $("html, body").animate({scrollTop:position}, 500, "easeInOutExpo");
         
        }

		//console.log('Fn_pageScroll='+position);
		//$("#pageScroll").css({ 'transform': 'translate3d(0px, -'+target_pos_fix+'px, 0px)'});
		//$("html,body").animate({ scrollTop: target_pos_fix }, speed, 'easeInOutExpo');
}

function Fn_each_items(){
	$('.linkArea').each(function () {
		
		var w = $(this).outerWidth();
		var h = $(this).outerHeight();
		$(this).parent().parent().parent().find('.inBtn').css({ 'width' : w+'px' ,  'height' : h+'px'  });
	
	});
	
	$('.parentWidth').each(function () {
		
		var w = $(this).parent().parent().innerWidth();
		var h = $(this).parent().parent().innerHeight();
		$(this).css({ 'width' : w+'px'  });
	
	});
	
	$('section.about .contentsWrap ul li span , body#rookie section#contentsArea .readWrap ul li span').each(function () {
		var w = $(this).parent().parent().outerWidth();
		var h = $(this).parent().parent().outerHeight();
		$(this).css({ 'width' : w+'px'  });
	});
	
	$('body#yell  .textContents ul li span').each(function () {
		var image_no = $(this).parent().parent().attr('data-no');
		var w = $(this).parent().parent().outerWidth();
		var h = $(this).parent().parent().outerHeight();
		$(this).css({ 'width' : w+'px' , 'background-image' : 'url(../../assets/img/yell/'+image_no+'/text.png) ', 'background-size':'100% auto' ,  'background-repeat':'no-repeat' });
	});
	
/*
	var about_li_count = 0;
	var about_li_delay = 100;
	var about_li_wait_count = 0;
	var about_li_wait_delay = 600;
	$('section.about .contentsWrap ul li').each(function () {
		if($(this).hasClass('wait')){ about_li_wait_count ++}
		about_li_count ++ ;
		var delay_fix = (about_li_count * about_li_delay)+(about_li_wait_count * about_li_wait_delay );
		$(this).css({ 'transition-delay' : delay_fix +'ms'  });
	});
*/
	
	
		$('.slick-slide ').each(function () {
			var classs = $(this).parent().parent().parent().parent().attr('class');
			var w = $(this).parent().parent().parent().parent().outerWidth();
			var h = $(this).parent().parent().parent().parent().outerHeight();
			$(this).width(w);
		});
	
	
}


$(window).on('load resize', function(){
// 処理を記載
	Fn_each_items();

});

var scroll_pos_top = 0;
var scroll_pos_top_current = 0;

$(window).on('scroll', function(){
// 処理を記載
    if(!global_menu_flag){
        var scroll_pos_top = $(window).scrollTop();

      if(scroll_pos_top > scroll_pos_top_current){
         //console.log('↓');


          $("body").addClass('globalHeaderHide').removeClass('globalHeaderCompact');;

           if(scroll_pos_top < 100){
               
               $("body").removeClass('globalHeaderHide globalHeaderCompact');
           }
          
         }else{
          //console.log('↑');


              if(scroll_pos_top > 100){
                $("body").addClass('globalHeaderCompact');
              }else{
                    $("body").removeClass('globalHeaderHide globalHeaderCompact');
              }

         }
        //console.log('scroll_pos_top='+scroll_pos_top);

        scroll_pos_top_current = scroll_pos_top;
        
        
        if($('#contentsMain').length){
            var contentsMain_pos = $('#contentsMain').offset().top;
        }else{
            var contentsMain_pos = $('#format').offset().top;
        }
         
        
        
        
        
        var header_h = $('#globalMenu .main').outerHeight();
        
        
        if(scroll_pos_top < contentsMain_pos - (header_h/2)){
            $("body").addClass('view_mainvisual');
        }else{
             $("body").removeClass('view_mainvisual');
        }
        
        
    }
});
 

 
 
$(function () {
var nowpage_url = location.href ;
var nowpage_hash = location.hash ;
var nowurl = nowpage_url.split(nowpage_hash);
//console.log('nowurl='+nowurl[0]);
   
   $(window).hashchange(function() {
       setTimeout(function(){
           var hashVar = location.hash.split('/');
          
           
           var target = $('#'+hashVar[1]);
                   

                   if(target.length) {
           
             
                               var position = target.offset().top - 140;
                               //console.log(position);
                               $('body,html').stop().animate({scrollTop:position}, 1500, "easeInOutExpo",function(){
                                 
                                 window.history.pushState({}, '', nowurl[0] );
                                 
                               });
           }
           
           
       },500);
   });



     setTimeout(function(){
        var urlHash = location.hash;
          //console.log('urlHash='+urlHash);
         
         var res = urlHash.split('#/');
           var target = $('#'+res[1]);
                
                //console.log(res[1]);
                if(target.length) {
 
                   $('body,html').stop().scrollTop(0);
                            var position = target.offset().top - 60;
                            console.log(position);
                            $('body,html').stop().animate({scrollTop:position}, 1500, "easeInOutExpo",function(){
                               
                               window.history.pushState({}, '', nowurl[0] );
                               
                             });
        }
        
        
     },500);

	
	$('#globalMenu .menuOpenBtn').on('click', function(){

        if($('body').hasClass('menuOpen')){
            global_menu_flag = false;
			$('body').removeClass('menuOpen');
		}else{
            global_menu_flag = true;
		   	$('body').addClass('menuOpen');
		}
         
        
    });
    $('#globalFixedMenu .menuOpenBtn').on('click', function(){

        if($('body').hasClass('menuFixedOpen')){

			$('body').removeClass('menuFixedOpen');
		}else{
		   	$('body').addClass('menuFixedOpen');
		}
         
        
    });
	
    $('.backtotopBtn , .footer__totop-btn').on('click', function(){
        
        
        
        var h = $("body").outerHeight();
        var ww = $(window).outerHeight();
        console.log(h);
        var goto = h;
        $(".backtotopBtn .rocket").animate({ top: -goto }, 1100,"easeInQuart");
        
        $("html,body").animate({ scrollTop: 0 }, 1000, 'easeInQuart', function(){
            
            $(".backtotopBtn .rocket").animate({ top: 0 }, 1);
        });
         
        
    });
    
    $('.nav__toggle-btn').on('click', function(){
        if($("body").hasClass('navOpen')){
            
            $("body").addClass('navClose');
            setTimeout(function(){
                $("body").removeClass('navOpen');
            },100);
            
            
        }else{
            $("body").removeClass('navClose');
            $("body").addClass('navOpen');
        }
        
    });
    
    
    $('.formCheckInput input[name="checkbox"]').on('click', function(){
       var target = $(this).attr('data-checktarget');
        
        if ($(this).prop("checked")) {
            $(target).addClass('active');
          } else {
            $(target).removeClass('active');
          }
        
    });
    
    
    
    $('.modalContents').on('click', function(){
        
        scrollLock = true;
        global_scroll_pos = $(window).scrollTop();
        
       var target = $(this).attr('data-entry');
        $('body').addClass('bodyLock modalWindowActive');
      
       $('#modalWindow .contentsArea').load(target+'?mode=modal #entryDetailData');
        
        
        var nowscroll_pos = $(window).scrollTop();
        //console.log('nowscroll_pos='+nowscroll_pos);
        //luxy.cancel();
        
        
    });
    
    
    $('#modalWindow .closeBg , #modalWindow .closeBtn').on('click', function(){
       $('body').addClass('modalWindowClose');
       setTimeout(function(){
           $('#modalWindow .contentsArea').empty();
           $('body').removeClass('bodyLock modalWindowActive modalWindowClose');
           $("html,body").scrollTop(global_scroll_pos);
           
           scrollLock = false;
       },1000);
        
    });
    
    $('.nav__menu a , .footer__links a').on('click', function(event){
        var href_url = $(this).attr('href');
        //console.log('client=' + event.clientX + ',' + event.clientY);
        event.preventDefault();
   
        $('body').addClass('coverEffextIn');
        
        $('body').append('<div id="coverEffext"><div class="bg" style="top:'+event.clientY+'px;left:'+event.clientX+'px;"></div><div class="bg" style="top:'+event.clientY+'px;left:'+event.clientX+'px;"></div></div>');
        
        setTimeout(function(){
             $('body').addClass('coverEffextZoom');
            var w = window.outerWidth;
            var h = window.outerHeight;
            if(w>h){
                var zoomSize = w*2.5;
            }else{
                var zoomSize = h*2.5;
            }
            
            
            $('#coverEffext .bg').width(zoomSize);
        },100);
        
        setTimeout(function(){
             location.href = href_url;
            //$('#coverEffext').remove();
        },1200);

        
        
    });
    
    
    $('.qaBox dt').on('click', function(event){
        
        if($(this).parent().hasClass('open')){
           
            $(this).parent().removeClass('open')
           
           }else{
           $(this).parent().addClass('open')
           }
        
        
     });
    
    
        
    $('.globalHeader .menuWrap .linkUnit ul li.hasChild .parent').on('click', function(event){
        
        if($(this).parent().hasClass('open')){
           
            $(this).parent().removeClass('open')
           
           }else{
           $(this).parent().addClass('open')
           }
        
        
     });
    


});


    	
   
function Fn_bodyInit(){
    	var scroll_body_h = $('.contents-body').outerHeight();
                
		$('body, #footerWrap').height(scroll_body_h);
    
    
        var header_h = $('.globalHeader').outerHeight();
    
    $('main').css({'padding-top':header_h+'px'});
    //console.log('header_h='+header_h);
    

              
}


var scrollLock = false;
var smoothScrollSpeed = 0.1;
var stagePos = {};
var smoothScrollY = 0;

function Fn_scrollUpdate(){
    
    if(!scrollLock){
        stagePos.top = $(window).scrollTop();
        //console.log('stagePos.top='+stagePos.top);
    }
    
    smoothScrollY += (stagePos.top - smoothScrollY)* smoothScrollSpeed;
    $(".mf-scroll-body").css({transform:'translate3d(0,'+(-smoothScrollY)+'px,0)'});
    
    //console.log('smoothScrollY='+smoothScrollY);
    
    
    
    
    $('.luxy-el').each(function(index, element){
        //console.log(index + ':' + $(element).text());
        
        
        var speed = $(element).attr('data-speed-y');
        
        $(element).css({transform:'translate3d(0,'+((-smoothScrollY)*speed)+'px,0)'});
        
      });
    
    
    
    
    $('#specialInformation .close').on('click',function(event){
        $('#specialInformation').remove();
    });
    
    
    if( stagePos.top > 200){
        $('body').addClass('menuFixedActive')
    }else{
        $('body').removeClass('menuFixedActive')
    }
    
    
}


var requestAnimationFrame = 
			window.requestAnimationFrame || window.mozRequestAnimationFrame ||
			window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
			window.requestAnimationFrame = requestAnimationFrame;
			


	
			(function loop(){
			    window.requestAnimationFrame(loop);
				//console.log('requestAnimationFrame ');
	           Fn_bodyInit();
                Fn_scrollUpdate();
			     
			     
                //console.log(scroll_now_pos);
                //$('.scroll-body').css({'transform':'translate3d(0px, -'+scroll_now_pos+'px, 0px)'})
                //$('.nav-menu').css({'transform':'translate3d(0px, '+scroll_now_pos+'px, 0px)'})
                
                
                
                //$('.main_kv').css({'bottom':'-'+ (scroll_now_pos/5) +'px'});
                //$('.page_head_cloud').css({'transform':'translate3d(-50%,'+ (scroll_now_pos*0.5) +'px, 0)'});
                //$('.page_head_title').css({'transform':'translate3d(-50%,'+ (scroll_now_pos*0.8) +'px, 0)'});
    

                
            
                
			})();
	

		

    