// JavaScript Document
window.onload = function() {

  // Make srcset
  $('.maincontent img').each(function (e)
  {
    var $target = $(this),
      $src = $(this).attr('src'),
      $srcset_1x = $src,
      $srcset_2x = $src.replace('/1x/', '/2x/'),
      $check_img = new Image(),
      $check_url = location.href + $srcset_2x.slice(1);

			$check_img.src = $srcset_2x;
			$check_img.onload = function () {
				setTimeout(function () {
					$target.attr('srcset', $srcset_1x + ' 1x, ' + $srcset_2x + ' 2x');
				}, 1);
			}
			$check_img.onerror = function () {
				console.log($srcset_2x + ' is not exixt.');
			}
    });
  
  
  // Adjust iframe
	$('p > iframe').each(function (e)
	{
		var ratio = $(this).attr('height') / $(this).attr('width');
		var wrapperWidth = $(this).parents('div').innerWidth();
		$(this).attr('width', wrapperWidth).attr('height', wrapperWidth * ratio);
  })


	// drawer
	$(".drawer").drawer();


	// smooth scroll
	$('a[href^=#]').click(function() {
		var speed = 400; // ミリ秒
		var href= $(this).attr("href");
		var target = $(href == "#" || href == "" ? 'html' : href);
		var position = target.offset().top;
		$('body,html').animate({scrollTop:position}, speed, 'swing');
		return false;
	});


	// $('.global-header-pc-navi li a img').hover(function(){
	// 	 $(this).attr('src', $(this).attr('src').replace('_off', '_on'));
	// 		 }, function(){
	// 				if (!$(this).hasClass('currentPage')) {
	// 				$(this).attr('src', $(this).attr('src').replace('_on', '_off'));
	// 	 }
	//  });


};

// PC MENU JP-EN
function change_navBtn(id){
	$('#jp-'+id).css('display','block');
	$('#en-'+id).css('display','none');
}

function reset_navBtn(id){
	$('#en-'+id).css('display','block');
	$('#jp-'+id).css('display','none');
}
