/* ---------------------------------------------------
 *
 * copyright(c) Creastitch Inc.
 * project - Vessel Hotel Development
 * script.js
 *
 * ---------------------------------------------------*/




/* ---------------------------------------------------
 * CONSOLELOG IE BUGFIX
 * ---------------------------------------------------*/
(function(){
	if(typeof window.console === 'undefined') window.console = {};
	if(typeof window.console.log !== 'function') window.console.log = function (){};
})();




/* ---------------------------------------------------
 * INDEXOF IE BUGFIX
 * ---------------------------------------------------*/
if(!Array.prototype.indexOf){
	Array.prototype.indexOf = function(target,index){
		if(isNaN(index)) index = 0;
		for(var i = index; i < target.length; i++){
			if(this[i] === target) return i;
		}
		return -1;
	};
}




/* ---------------------------------------------------
 * OS & BROWSER & USERAGENT
 * ------------------------------------------------ */
var
	uaStr = window.navigator.userAgent.toLowerCase(),
	appVer = window.navigator.appVersion.toLowerCase(),
	isDevice = false,
	isIE = false,
	isIEOld = false,
	isEdge = false,
	ieVer = false,
	isWebkit = false,
	isFirefox = false,
	isTouch = false,
	isOpacity = true,
	isTransform = true,
	isTransition = true
;

var ua = (function(u){
	return {
		Tablet: (u.indexOf('windows') != -1 && u.indexOf('touch') != -1) || u.indexOf('ipad') != -1 || (u.indexOf('android') != -1 && u.indexOf('mobile') == -1) || (u.indexOf('firefox') != -1 && u.indexOf('tablet') != -1) || u.indexOf('kindle') != -1 || u.indexOf('silk') != -1 || u.indexOf('playbook') != -1,
		Mobile: (u.indexOf('windows') != -1 && u.indexOf('phone') != -1) || u.indexOf('iphone') != -1 || u.indexOf('ipod') != -1 || (u.indexOf('android') != -1 && u.indexOf('mobile') != -1) || (u.indexOf('firefox') != -1 && u.indexOf('mobile') != -1) || u.indexOf('blackberry') != -1,
		IE: u.indexOf('trident') != -1 || u.indexOf('msie') != -1,
		Edge: u.indexOf('edge') != -1,
		Webkit: u.indexOf('chrome') != -1 || u.indexOf('safari') != -1,
		Firefox: u.indexOf('firefox') != -1
	};
})(uaStr);


/* SMARTPHONE
 * ------------------------------------------------ */
if(ua.Tablet || ua.Mobile) isDevice = true;
if(isDevice){
	$('html').addClass('device');
}else{
	$('html').addClass('no-device');
}


/* IE
 * ------------------------------------------------ */
if(ua.IE){
	isIE = true;
	var ieAry = /(msie|rv:?)\s?([\d\.]+)/.exec(uaStr);
	ieVer = (ieAry) ? ieAry[2] : '';
	ieVer = Math.floor(ieVer);
	$('html').addClass('ie');
	$('html').addClass('ie' + ieVer);
	if(ieVer <= 8){
		isIEOld = true;
		$('html').addClass('ieOld');
	}
}


/* EDGE
 * ------------------------------------------------ */
if(ua.Edge){
	isEdge = true;
	$('html').addClass('edge');
}


/* WEBKIT
 * ------------------------------------------------ */
if(ua.Webkit){
	isWebkit = true;
}




/* ---------------------------------------------------
 * GET ROOTPATH
 * --------------------------------------------------- */
var
	rootURL = '',
	rootPath = ''
;
(function(){
	var
		file = '_assets/js/common/script.js',
		reg = new RegExp('(^|.*\/)' + file + '$'),
		script = document.getElementsByTagName('script'),
		i = script.length
	;
	while(i--){
		var src = script[i].src.replace(/\?.*?$/g, '');
		var match = src.match(reg);
		if(match){
			rootURL = match[1];
			break;
		}
	}
	rootPath = rootURL.slice(rootURL.indexOf(location.hostname) + location.hostname.length);
//console.log('rootURL:' + rootURL);
//console.log('rootPath:' + rootPath);
}());




/* ---------------------------------------------------
 * LOCATION PARAMETER
 * ------------------------------------------------ */
var pagePrm = new Object;
var pagePrmLocation = location.search.substring(1).split('&');
for(var i=0; pagePrmLocation[i]; i++){
	var pagePrmVal = pagePrmLocation[i].split('=');
	pagePrm[pagePrmVal[0]] = pagePrmVal[1];
}
//console.log(pagePrm);
// EX: pagePrm.hoge




/* ---------------------------------------------------
 * Smooth Scroll
 * ------------------------------------------------ */
$(window).on('load',function(){

	/* CLICK */
	$('a[href^="#"]').on('click', function(){
		if(!$(this).hasClass('js-noScroll')){
			var href = $(this).attr('href');
			smoothScroll({
				href: href,
				speed: 500,
				easing: 'easeOutExpo',
				fixed: '.g-header' //EX.'#header'
			});
			return false;
		}
	});

	/* LOAD */
	var hash = location.hash;
	if(hash){
		//$(window).scrollTop(0, 0);
		setTimeout(function(){
			smoothScroll({
				href: hash,
				speed: 1,
				easing: 'easeOutExpo'
			});
		}, 1000);
	}
});
function smoothScroll(e){
	var
		speed = e.speed ? e.speed : 750,
		easing = e.easing ? e.easing : 'easeOutExpo',
		target = $(e.href === '#' || e.href === '' ? '#PAGETOP' : e.href),
		position = (target.length > 0) ? target.offset().top : 0,
		posMinus = (e.href === '#PAGETOP') ? 0 : (e.fixed ? $(e.fixed).outerHeight() : 0),
		zoom = ($('html').css('zoom') != 1 && !(isNaN($('html').css('zoom')))) ? Number($('html').css('zoom')) : 1
	;
	if(ua.Mobile){
		$('html, body').animate({scrollTop: (position - posMinus) * zoom}, speed, easing);
	}else{
		$('html, body').animate({scrollTop: (position)}, speed, easing);
	}
	
}




/* ---------------------------------------------------
 * Link Invalid
 * ------------------------------------------------ */
$(window).on('load',function() {
	$('.js-link-invalid').click(function(){
		return false;
	})
}); //END jQuery




/* ---------------------------------------------------
 * Tel Link
 * ------------------------------------------------ */
$(function(){
	var ua = navigator.userAgent;
	if(ua.indexOf('iPhone') > 0 || ua.indexOf('Android') > 0){
			$('.js-link-tel').each(function(){
					var str = $(this).text();
					$(this).html($('<a class="e-link">').attr('href', 'tel:' + str.replace(/-/g, '')).append(str + '</a>'));
			});
	}
}); //END jQuery




/* ---------------------------------------------------
 * RIGHT CLICK PROHIBITION
 * ------------------------------------------------ */
/*
$(function(){
	$('.js-prohibition').on('contextmenu',function(e){
		return false;
	});
});
*/




/* ---------------------------------------------------
 * 予約ボタン → モーダルウインドウ
 * ------------------------------------------------ */
$(function(){

	$('.js-modal_trigger').on('click', function(){
		$('html').toggleClass('is-modal_active');
		return false;
	});
	
	$('.js-modal_close').on('click', function(){
		$('html').removeClass('is-modal_active');
	});

}); //END jQuery




/* ---------------------------------------------------
 * 端末によってform要素削除
 * ------------------------------------------------ */
$(document).ready(function(){
	if(ua.Mobile){
		$('.g-reserve-input__inner3, .g-reserve-input__inner4, .g-reserve-input__inner5').addClass('is-hide');
	} else {
		$('.g-reserve-input__inner6').addClass('is-hide');
	}
}); // jQuery END




/* ---------------------------------------------------
 * アンカーリンク スマホ時に開閉パネル化
 * ------------------------------------------------ */
if(ua.Mobile) {
	$(function(){
		$('.js-ancselect').on('click', function(){
			$(this).toggleClass('is-on');
		});
	});
}




/* ---------------------------------------------------
 * Hamburger Menu for Mobile
 * ------------------------------------------------ */
if(ua.Mobile){
	$(function(){

		$('.js-navButton').on('touchstart', function(){
			if($(this).next('.g-nav').not(':animated').length >= 1){
				$('html').toggleClass('is-hhmenu-open');
				$(this).next('.g-nav').slideToggle();
				$('.g-nav__member-list, .g-nav__lang-list').hide();
			}
		});

		$('.u-cover').on('click', function(){
			$('html').removeClass('is-hhmenu-open');
			$('.g-nav').slideUp();
			$('.g-nav__member-list, .g-nav__lang-list').hide();
		});

	}); //END jQuery
}



/* ---------------------------------------------------
 * 要素入れ替え スマホ
 * ------------------------------------------------ */
/*
if(isDevice) {
	$(document).ready(function(){
		$('.js-membermenu-list').before($('.js-langlist'));
	});
}
*/




/* ---------------------------------------------------
 * LANG SELECT
 * ------------------------------------------------ */
$(function(){

	if(isDevice) {
		$('.js-langlist').on('click', function(){
			$(this).children('.g-nav__lang-list').stop().slideToggle();
			$('.g-nav__member-list').slideUp();
		});
	} else {
		$('.js-langlist').on({
			'mouseenter':function(){
				$(this).children('.g-nav__lang-list').addClass('g-nav__lang-list___on');
				$(this).children('.g-nav__lang-list').stop().slideDown();
			},
			'mouseleave':function(){
				$(this).children('.g-nav__lang-list').removeClass('g-nav__lang-list___on');
				$(this).children('.g-nav__lang-list').stop().slideUp();
			}
		});
	}
}); // jQuery END




/* ---------------------------------------------------
 * MEMBER MENU SELECT
 * ------------------------------------------------ */
	if(ua.Mobile) {
		$(function(){
			$('.js-membermenu-list dt').on('click', function(){
				$(this).next('.g-nav__member-list').stop().slideToggle();
				$('.g-nav__lang-list').slideUp();
			});
		}); // jQuery END
	}




/* ---------------------------------------------------
 * MEMBER MENU SELECT
 * ------------------------------------------------ */
$(window).on('load resize', function(){
	if(ua.Mobile) {
		$('.g-reserve-input__inner3 select, .g-reserve-input__inner4 select, .g-reserve-input__inner5 select').prop("disabled", true);
		$('.g-reserve-input__inner6 select').prop("disabled", false);
	} else {
		$('.g-reserve-input__inner3 select, .g-reserve-input__inner4 select, .g-reserve-input__inner5 select').prop("disabled", false);
		$('.g-reserve-input__inner6 select').prop("disabled", true);
	}
}); // jQuery END


// 2023.07.26 追記


/* ---------------------------------------------------
 * 空室検索　日付
 * ------------------------------------------------ */

$(function () {
  var scrollPosition;
  $(".js-modal_trigger").on("click", function () {
    scrollPosition = $(window).scrollTop();
    $("body").addClass("g-modal_fixed").css({
      top: 0,
    });
  });
  $(".c-vacantBanner").on("click", function () {
    // バナーで空室検索オープン時、日付を付与
    $("#checkin_date").val(getToday());
  });
  $(".js-modal_close").on("click", function () {
    // 空室検索を閉じるとき、日付を空に
    // $("#checkin_date").val("");
    $("body").removeClass("g-modal_fixed").css({
      top: 0,
    });
    window.scrollTo(0, scrollPosition);
  });
});

$(document).ready(function() {
  // 日付を取得して要素のテキストを更新する
  $('.c-vacantBanner__date').text(getToday(true));
});

// 今日の日付を返す 
// includeWeekday　true：曜日付き　false：曜日なし
function getToday(includeWeekday) {
  let date = new Date();
  let y = date.getFullYear();
  let m = String(date.getMonth() + 1).padStart(2, '0');
  let d = String(date.getDate()).padStart(2, '0');

  if (includeWeekday) {
    let day = ['日', '月', '火', '水', '木', '金', '土'][date.getDay()];
    return y + '/' + m + '/' + d + '（' + day + '）';
  } else {
    return y + '/' + m + '/' + d;
  }
}

/* ---------------------------------------------------
 * pick upバナー
 * ------------------------------------------------ */

$(function () {
  var select = ".c-pickUp__imageList";
  if ($(select).length > 0) {
    $(select).slick({
      autoplay: true,
      autoplaySpeed: 2000,
      speed: 800,
      dots: false,
      arrows: false,
      infinite: true,
      slidesToShow: 3,
      slidesToScroll: 1,
      responsive: [
        {
          breakpoint: 768,
          settings: {
            autoplay: true,
            slidesToShow: 1,
            slidesToScroll: 1,
            centerMode: true,
	          centerPadding: "11.9%",
          }
        },
      ],
    });
  }
}); 


