$(document).ready(function(){
  // Smooth Scroll add 2020.04.23
  var urlHash = location.hash;
  if(urlHash) {
      $('body,html').stop().scrollTop(0);
      setTimeout(function(){
          var adjust = 80;
          var target = $(urlHash);
          var position = target.offset().top - adjust;
          $('body,html').stop().animate({scrollTop:position}, 500);
      }, 800); //speed
  }
  else {
    $('a[href^="#"]').not('.no-scroll').click(function(){
      var adjust = 80;
      var speed = 500; //speed
      var href= $(this).attr("href");
      var target = $(href == "#" || href == "" ? 'html' : href);
      var position = target.offset().top - adjust;
      $('body,html').animate({scrollTop:position}, speed, 'swing');
      return false;
    });
  }

  $('#silde-interior').slick({
    prevArrow: $('.prev'),
    nextArrow: $('.next'),
  });

  var $slider = $('#silde-interior');


$(document).ready(function(){
	$('.snap-slider-main').slick({
		slidesToShow: 1,
		slidesToScroll: 1,
		fade: true,
		arrows: false,
		asNavFor: '.snap-slider-nav'
	});

	var slidesToshow_val = 2;
	var slidesToshow_leng = $(".snap-slider-nav li").length;
	if( slidesToshow_leng > slidesToshow_val ) {
		slidesToshow_val = slidesToshow_leng;
	}
	$('.snap-slider-nav').slick({
		slidesToShow: slidesToshow_val,
		slidesToScroll: 1,
		asNavFor: '.snap-slider-main',
		// centerMode: true,
		// centerPadding: '0',
		focusOnSelect: true,
		arrows: false
	});
});
  var $status = $('.pagingInfo');
  var $count_slick = $slider.slick("getSlick").slideCount;
  $status.html('<span>1</span>'+' / '+$count_slick);
  $slider.on('afterChange', function(event, slick, currentSlide, nextSlide){
    var i = (currentSlide ? currentSlide : 0) + 1;
    $status.html('<span>'+i+'</span>' + ' / ' + slick.slideCount);
  });
});

$('.btn-base-lang').click(function(){
  $(this).next().toggleClass('dropdown-lang-active');
});

$('.open-menu').click(function(){
  	$('#slide-nav').attr('style','left: 0px;');
  	$('.open-menu').attr('style','display:none; transition: opacity 1s ease-out; opacity: 0;');
  	$('.close-menu').attr('style','display:block; transition: opacity 1s ease-in; opacity: 1;');
  	$('.modal_bg').attr('style','position: fixed;top: 0px;left: 0px;display: block;');
});

$('.close-menu').click(function(){
	$('#slide-nav').attr('style','left: -300px;');
  	$('.close-menu').attr('style','display:none; transition: opacity 1s ease-out; opacity: 0;');
  	$('.open-menu').attr('style','display:block; transition: opacity 1s ease-in; opacity: 1;');
  	$('.modal_bg').attr('style','position: fixed;top: 0px;left: 0px;display: none;');
});

$('#mainvisual').slick({
  slidesToShow: 1,
  slidesToScroll: 1,
  centerPadding: '260px',
  dots: true,
  centerMode: true,
  speed: 800,
  autoplay: true,
  autoplaySpeed: 3000,
  variableWidth: true,
  focusOnSelect: true,
  responsive: [
    {
      breakpoint: 770,
      settings: {
        dots: true,
        infinite: true,
        centerPadding: '60px',
        slidesToShow: 1,
        adaptiveHeight: true
      }
    },
    {
      breakpoint: 450,
      settings: {
        arrows: false,
        centerMode: true,
        variableWidth: false,
        centerPadding: '0px',
        slidesToShow: 1
      }
    }
  ]
});


// GO TO TOP //
$( window ).scroll( function () {
	if ( $( this ).scrollTop() >= 250 ) { 
		$( '.gototop' ).fadeIn( 250 );
	} else {
		$( '.gototop' ).fadeOut( 250 );
	}
});
$( '.gototop' ).click( function () { // When arrow is clicked
	$( 'body,html' ).animate( {
		scrollTop: 0 }, 1000 );
});


// guest-snap detail
// $(document).ready(function(){
//   $('.TopPage #menu .menu-logo .hide-top').remove();
//   $('.TopPage #menu .menu-logo').append('<h1><a href="/th/"><img src="/th/assets/images/commons/logo.svg" alt="logo"></a></h1>');
// });

$.fn.equalHeights = function(){
	var max_height = 0;
	$(this).each(function(){
		max_height = Math.max($(this).height(), max_height);
	});
	$(this).each(function(){
		$(this).height(max_height);
	});
};
$(document).ready(function(){
  $('.wp-title').equalHeights();
  $('.info-wp-title').equalHeights();
  $('.snap-wp-title').equalHeights();
  $('.topics-wp-title').equalHeights();
  $('.wp-snaptext').equalHeights();
  $('.snap-shop').equalHeights();
  $('.customer-wp-title').equalHeights();
  $('.wp-customertext').equalHeights();
});


$(document).ready(function(){
	$('.snap-slider-main').slick({
		slidesToShow: 1,
		slidesToScroll: 1,
		fade: true,
		arrows: false,
		asNavFor: '.snap-slider-nav'
	});

	var slidesToshow_val = 1;
	var slidesToshow_leng = $(".snap-slider-nav li").length;
	if( slidesToshow_leng > slidesToshow_val ) {
		slidesToshow_val = slidesToshow_leng;
	}
	$('.snap-slider-nav').slick({
		slidesToShow: slidesToshow_val,
		slidesToScroll: 1,
		asNavFor: '.snap-slider-main',
		// centerMode: true,
		// centerPadding: '0',
		focusOnSelect: true,
		arrows: false
	});
});