﻿// JavaScript Document

// 画面制御用javascript 呼出し
document.write("<script src='/BousaiPublic/html/common/script/icon_display.js' type='text/javascript'></script>");

//init
var oh = 0;
var nh = 0;
var UA, OS = "";

(function($){

	//サイズ変更基準%を設定
	bg = '82%';
	df = '75%';
	sm = '68%';

})(jQuery);

window.onload = function(){
	// キャッシュ削除のためリロード
	var loc = location.href;
	if (loc.indexOf(".aspx")==-1){
		if (window.name != "reloadFlag"){
			location.reload(true);
			window.name = "reloadFlag";
		} else if (window.name = "reloadFlag"){
			window.name = "";
		}
	}

	// icon_display.js メイン処理
	if($(document.getElementsByName("menu_iframe"))!=null) { 

		// ヘッダメニュー制御処理
		updateContentsMain();
	}

	//ヘッダクリック要素追加処理
	$('#header_normal').click(function(e){
		if(e.pageX > $('#header_normal').position().left + 15 && e.pageX < $('#header_normal').position().left + 280 ){
			if(e.pageY > $('#header_normal').position().top + 15 && e.pageY < $('#header_normal').position().top + 60 ){
				//alert($('#header_normal').position().left + '|' + $('#header_normal').position().top + '|' + e.pageX + '|' + e.pageY);
				//alert($("#pankuzu > span > a").attr("href"));
				if($("#pankuzu a").attr("href") == undefined){
					document.location.reload();
				} else {
					document.location.href=$("#pankuzu a").attr("href");
				}
			}
		}
	});

	$('#header_emergency').click(function(e){
		if(e.pageX > $('#header_emergency').position().left + 15 && e.pageX < $('#header_emergency').position().left + 280 ){
			if(e.pageY > $('#header_emergency').position().top + 15 && e.pageY < $('#header_emergency').position().top + 60 ){
				//alert($('#header_emergency').position().left+ '|' + $('#header_emergency').position().top + '|' + e.pageX + '|' + e.pageY);
				//alert($("#pankuzu > span > a").attr("href"));
				if($("#pankuzu a").attr("href") == undefined){
					document.location.reload();
				} else {
					document.location.href=$("#pankuzu a").attr("href");
				}
			}
		}
	});

	//ヘッダクリック要素マウスオーバー追加処理
	$('#header_normal').mousemove(function(e){
		if(e.pageX > $('#header_normal').position().left + 15 && e.pageX < $('#header_normal').position().left + 280 ){
			if(e.pageY > $('#header_normal').position().top + 15 && e.pageY < $('#header_normal').position().top + 60 ){
				//alert($('#header_normal').position().left + '|' + $('#header_normal').position().top + '|' + e.pageX + '|' + e.pageY);
				$('#header_normal').css('cursor','pointer');
			} else {
				$('#header_normal').css('cursor','default');
			}
		} else {
			$('#header_normal').css('cursor','default');
		}
	});

	$('#header_emergency').mousemove(function(e){
		if(e.pageX > $('#header_emergency').position().left + 15 && e.pageX < $('#header_emergency').position().left + 280 ){
			if(e.pageY > $('#header_emergency').position().top + 15 && e.pageY < $('#header_emergency').position().top + 60 ){
				//alert($('#header_emergency').position().left+ '|' + $('#header_emergency').position().top + '|' + e.pageX + '|' + e.pageY);
				$('#header_emergency').css('cursor','pointer');
			} else {
				$('#header_emergency').css('cursor','default');
			}
		} else {
			$('#header_emergency').css('cursor','default');
		}
	});
	


	//ブラウザ判定	
	UA = navigator.userAgent.toLowerCase();
	OS = navigator.platform.toLowerCase();

	// ハングル・簡体字の文字化け対応
	if( UA.indexOf("safari") != -1 && OS.indexOf("win") != -1){
		//ハングル、簡体字ページのfont-family
		if(document.getElementsByTagName("html")[0].lang === "zh-CN" || document.getElementsByTagName("html")[0].lang === "ko"){

			document.body.style.fontFamily = "SimSun";

			$('iframe').each(
				function() {
					$("body", $(this).contents()).css("font-family", "SimSun");
				}
			);

		//繁体字のfont-family
		} else if(document.getElementsByTagName("html")[0].lang === "zh"){

			document.body.style.fontFamily = "MingLiU";

			$('iframe').each(
				function() {
					$("body", $(this).contents()).css("font-family", "MingLiU");
				}
			);

		}
	}

	// 災害情報テーブルのtr調整
	funcSetTrHeight();
	// 防災リンクフレームの高さを調整
	funcAdjustBousaiLinkFrameHeight();

	// トップページのタブクリックイベントリスナーadd
	if($("#inc_top_iframe04-01") != null && $("#inc_top_iframe04-02") != null){

		$("#inc_top_iframe04-01").css("display", "");
		$("#inc_top_iframe04-02").css("display", "none");
	
		if($("#information_bar_01_L").length != 0){
			$("#information_bar_01_L").click(function(){
				$(".tab01").fadeIn(0);
				$("#inc_top_iframe04-01").css("display", "");
				$(".tab02").fadeOut(0);
				$("#inc_top_iframe04-02").css("display", "none");
			});
		}
		if($("#information_bar_02_L").length != 0){
			$("#information_bar_02_L").click(function(){
				$(".tab01").fadeOut(0);
				$("#inc_top_iframe04-01").css("display", "none");
				$(".tab02").fadeIn(0);
				$("#inc_top_iframe04-02").css("display", "");
			});
		}

	}
	
	if($("#inc_top_iframe05-01") != null && $("#inc_top_iframe05-02") != null && $("#inc_top_iframe05-03") != null){

		$("#inc_top_iframe05-01").css("display", "");
		$("#inc_top_iframe05-02").css("display", "none");
		$("#inc_top_iframe05-03").css("display", "none");
	
		if($("#information_bar_01_R").length != 0){
			$("#information_bar_01_R").click(function(){
				$(".tab03").fadeIn(0);
				$("#inc_top_iframe05-01").css("display", "");
				$(".tab04,.tab05").fadeOut(0);
				$("#inc_top_iframe05-02,#inc_top_iframe05-03").css("display", "none");
			});
		}
		if($("#information_bar_02_R").length != 0){
			$("#information_bar_02_R").click(function(){
				$(".tab04").fadeIn(0);
				$("#inc_top_iframe05-02").css("display", "");
				$(".tab03,.tab05").fadeOut(0);
				$("#inc_top_iframe05-01,#inc_top_iframe05-03").css("display", "none");
			});
		}
		if($("#information_bar_03_R").length != 0){
			$("#information_bar_03_R").click(function(){
				$(".tab05").fadeIn(0);
				$("#inc_top_iframe05-03").css("display", "");
				$(".tab03,.tab04").fadeOut(0);
				$("#inc_top_iframe05-01,#inc_top_iframe05-02").css("display", "none");
			});
		}

	}

	//文字サイズ更新チェック
	setInterval(
		function(){
			nh = $('#pankuzu span').height();
			if(nh != oh){
				funcSetTrHeight();
				funcAdjustBousaiLinkFrameHeight();
			}
			oh = $('#pankuzu span').height();
		}
		, 100
	);

}

// フォントサイズ変更
function funcSetFontSize(per){

	if(per === 'bg'){
		fn = bg;
	}
	else if(per === 'df') {
		fn = df;
	}
	else if(per === 'sm') {
		fn = sm;
	}
	document.body.style.fontSize = fn;

}

//初期表示時の防災リンクフレームの高さ調整
function funcAdjustBousaiLinkFrameHeight(){

	var cl1 = $('div.column1');
	var cr1 = $('div.column2');
	var elm = $('div.column1 div.information_L');
	var elm1 = $('div.column1 #information_L');
	var elm2 = $('div.column1 div.information_R');
	var elm3 = $('div.column1 #information_R');

	if($(cl1) != null && $(cr1) != null && $(elm) != null){

		var hl = 0;		//左column高さ
		var hr = 0;		//右column高さ
		var hh = elm.height();	//タブコンテンツheight
		var mh = 350;

		//左カラムの高さ
		if(cl1) hl = $(cl1).outerHeight(true);
	
		//右カラムの高さ
		if(cr1) hr = $(cr1).outerHeight(true);
	
		//防災リンクフレームの高さを設定
		if(elm){
			var vh = 0;	//設定値
			if(hl - hr < 0){
				vh = hh + (hr - hl);
			} else if (hl - hr > 0){
				if(hh > mh && hh + (hr - hl) > mh){
					vh = hh + (hr - hl);
				} else {
					vh = mh;
				}
			} else {
				vh = hh;
			}
			$(elm).css("height", vh + 'px');
			$(elm1).css("height", vh + 'px');
			$(elm2).css("height", vh + 'px');
			$(elm3).css("height", vh + 'px');
		}
	}

}

//災害情報tableのtr高さ調整
function funcSetTrHeight(){

	var if1 = $('.top_emergency_iframe03-01 table');
	var if2 = $('.top_emergency_iframe03-02 table');

	if($(if1)[0] != null && $(if2)[0] != null){

		var trl = $(if1)[0].rows;
		var trr = $(if2)[0].rows;
		
		for(var i=0; i < trl.length; i++){
			
			var t1 = trl[i];
			var t2 = trr[i];
			
			// CSS初期化
			$(t1).css('height', '');
			$(t2).css('height', '');

			// 設定する高さ
			var th1 = $(t1).height() + 1;
			var th2 = $(t2).height() + 1;

			if($(t1).height() > $(t2).height()){
				$(t1).css('height', th1 + 'px');
				$(t2).css('height', th1 + 'px');
			}else if($(t2).height() > $(t1).height()){
				$(t1).css('height', th2 + 'px');
				$(t2).css('height', th2 + 'px');
			}else{
				$(t1).css('height', th1 + 'px');
				$(t2).css('height', th2 + 'px');
			}

		}

	}

}

//リストの選択アイテムcss変更
function funChangeCSS(num) {

	var tul = $("iframe_inner02");
	
	if($(tul) != null){

		var tli = tul.getElementsByTagName("li");
		for(var i=0; i<tli.length; i++){
			var atg = tli[i].getElementsByTagName("a");
			atg[0].className = (i == num) ? "list_on" : "list_off";
		}

	}

}

//中間ページを開き、指定URLに遷移
function funRedirect(url){

	// location
	//var path = window.location.pathname;
	var path = "/BousaiPublic/html";
	//path = path.substr(0, path.indexOf("/html")) + "/html";
	window.open(path + "/common/redirect.html?url=" + url,"中間ページ");

}

//中間ページを開き、指定URLに遷移新版
function funRedirect_new(obj){

	// location
	//var path = window.location.pathname;
	var path = "/BousaiPublic/html";
	//path = path.substr(0, path.indexOf("/html")) + "/html";
	window.open(path + "/common/redirect.html?url=" + obj.getAttribute('href'),"中間ページ");

}

