//iframeのキャッシュ防止 ソースにパラメーター付与
var iframeElm = document.getElementsByClassName("footer_frame");
if (iframeElm[0]){
	iframeElm[0].setAttribute("src", "/footer?" + Math.floor(Math.random()*10000));
}
jQuery(function($){
	$('iframe.footer_frame').on("load",function(){
		var header = $('iframe.header').contents();
		var footer = $('iframe.footer_frame').contents();

		var footerBg = function(){
			if ($(window).width() > 769) {
				footer.find('body').attr('style','background:rgb(13, 185, 252)!important;padding-top:0!important;');
			}else{
				footer.find('body').attr('style','background:#62bcfe!important;padding-top:0!important;');
				footer.find('.upper').attr('style','padding:10px 15px;');
			}
		}
		// ヘッダーの高さ取得
		var getHeaderHeight = function(){
			var headerHeight = header.find('.top_header').outerHeight();
			return headerHeight;
		}

		// フッターの高さ取得
		var getFooterHeight = function(){
			var copyright = footer.find('.copyright');
			var upper = footer.find('.upper').outerHeight();
			var inner = footer.find('.inner').outerHeight();
			var bottom = footer.find('.bottom').outerHeight();
			// PCサイズのbottomの高さ取得
			if (copyright.css('margin-bottom') && copyright.css('margin-top')) {
				var mb = Number(copyright.css('margin-bottom').replace('px',''));
				var mt = Number(copyright.css('margin-top').replace('px',''));
				bottom = bottom + mb + mt;
			}
			return upper + inner + bottom;
		}

		// フッターをwindow下部に固定
		var setFooterBottom = function(){
			var wh = window.innerHeight;
			var dh = $('#mypage001').outerHeight();
			var fh = getFooterHeight();
			if (wh < dh+fh) {
				$('#frame_footer').attr("style","top:" + (wh-fh) + "px;");
				$('#frame_footer').attr("style","position:static;");
			}else {
				$('#frame_footer').attr("style","position:absolute;");
				$('#frame_footer').attr("style","top:" + (wh-fh) + "px;");
			}
		}

		footerBg();
		$('iframe.header').height(getHeaderHeight());
		// bodyにtransition: 0.6sが設定されているため
		setTimeout(function(){
			$('iframe.footer_frame').height(getFooterHeight());
		},600);
		setFooterBottom();

		// リサイズ時の処理
		$(window).resize(function(){
			$('iframe.header').height(getHeaderHeight());
			$('iframe.footer_frame').height(getFooterHeight());
			footerBg();
			setFooterBottom();
		});

		// ヘッダー伸縮
		// PC
		header.find('#global_nav ul.common li.has_child').each(function(){
			$(this).hover(function(){
				$('iframe.header').height($(this).find('ul').outerHeight() + getHeaderHeight());
			},function(){
				$('iframe.header').height(getHeaderHeight());
			});
		});
		// スマホ
		header.find('.top_header input[type="button"]').each(function(){
			$(this).on("click",function(){
				var spHeight = (header.find('nav').hasClass('open'))?header.find('nav').height():0;
				$('iframe.header').height(spHeight+getHeaderHeight());
			});
		});

		// 言語選択伸縮
		header.find('.side_tool div').each(function(){
			$(this).hover(function(){
				setTimeout(function(){
					$('iframe.header').height(header.find('.side_tool div ul').outerHeight() + getHeaderHeight());
				},200);
			},function(){
					$('iframe.header').height(getHeaderHeight());
			});
		});

		// フッター伸縮
		footer.find('.upper > ul > li').each(function(){
			$(this).find('.is_accordion').on("click",function(){
					setTimeout(function(){
						$('iframe.footer_frame').height(getFooterHeight());
					},400);
			});
		});
	});
});

