﻿/*////// set Variable //////////////////////////////////////////////////////////////////////////*/

var navi_dirPath = "/foreign/";
var lang_array = new Array("english","chineses","chineset","korean","french","thai");
var onLoadFlg;

/*////// shared Variable ///////////////////////////////////////////////////////////////////////*/

var textCookieName = "HiroshimaTourText";

/*////// shared function ///////////////////////////////////////////////////////////////////////*/
//GetElementClass
function getElementsByClassName(className, pElement){
	var d = document, nodes = [];
	if(d.getElementsByClassName){
		nodes = (pElement||d).getElementsByClassName(className);
		return nodes.length > 0 ? nodes : null;
	}else{
		var cls, item;
		var items = (pElement || d).getElementsByTagName("*");
		for(var i = 0, l = items.length; i < l; i++){
			item = items[i];
			if(item.className){
				cls = item.className.split(/\s+/);
				for(var k = 0, kl = cls.length; k < kl; k++){
					if(cls[k]==className){
					nodes[nodes.length] = item; break;
					}
				}
			}
		}
		return nodes.length > 0 ? nodes : null;
	}
}

// cookie取得
function getCookie(name){
	if(!name) return;
	var val = "";
	var cookieName = name+"=";
	var tmpCookie = document.cookie + ";";
	var start = tmpCookie.indexOf(cookieName);
	if (start != -1) {
		var end = tmpCookie.indexOf(";", start);
		val = tmpCookie.substring(start + cookieName.length, end);
	}
	return val;
}

// cookie保存
function setCookie(name,value){
	if(!name || !value) return;
	var cookieName = name+"=";
	var exp = new Date();
	exp.setTime(exp.getTime() + 31536000000);
	document.cookie = cookieName + value + "; path=/" + "; expires=" + exp.toGMTString();
}

/*////// optional function /////////////////////////////////////////////////////////////////////*/
// 文字拡大・縮小
function textSizeUp(){
	var currentSize = document.body.style.fontSize;
	var selectSize;
	if(!currentSize) currentSize = "90%";
	if (currentSize=="80%"){
		selectSize = "90%";
	} else if(currentSize=="90%") {
		selectSize = "110%";
	} else if(currentSize=="110%") {
		selectSize = "130%";
	} else if(currentSize=="130%") {
		alert("You cannot enlarge the size of the character more.");
		selectSize = "130%";
	} else {
		selectSize = "90%";
	}
	document.body.style.fontSize = selectSize;
	setCookie(textCookieName,selectSize);
}
//
function textSizeDown(){
	var currentSize = document.body.style.fontSize;
	var selectSize;
	if(!currentSize) currentSize = "90%";
	if (currentSize=="130%"){
		selectSize = "110%";
	} else if(currentSize=="110%") {
		selectSize = "90%";
	} else if(currentSize=="90%") {
		selectSize = "80%";
	} else if(currentSize=="80%") {
		alert("You cannot reduce the size of the character more.");
		selectSize = "80%";
	} else {
		selectSize = "90%";
	}
	document.body.style.fontSize = selectSize;
	setCookie(textCookieName,selectSize);
}
function textSizeDefault(){
	var currentSize = "90%";
	document.body.style.fontSize = currentSize;
	setCookie(textCookieName,currentSize);
}

//ナビゲーション
function naviFun(){
	var thisPath = new String(window.location.pathname);
	thisPath = thisPath.replace(/(.*)index\..*/,"$1");
	var thisPro = new String(window.location.protocol);
	var thishost = new String(window.location.host);
	var thisDomain = thisPro + "\/\/" + thishost;
//
	subCateFun();
	gnaviFun('tmp_gnavi',1);
	gnaviFun('tmp_tab_menu',2);
//
	function subCateFun(){
		for(var i = 0; i < lang_array.length; i++){
			if(thisPath.match(lang_array[i])){
				navi_dirPath = navi_dirPath + lang_array[i] + "/";
				break;
			}
		}	
	}
//
	function flgFun(menuName,num,num2,flg){
		if(menuName == swMenuObj){
			openSwitch(num,num2,flg);
		}else if(menuName == tabMenuObj){
			openTab(num,num2,flg);
		}
	}
//
	function gnaviFun(area,level){
		var gnObj = document.getElementById(area);
		var panObj = document.getElementById("tmp_pankuzu");
		if(gnObj){
			var gnElm = gnObj.getElementsByTagName("a");
			var gnElm2 = gnObj.getElementsByTagName("img");	
			if (panObj){
				var panElm = panObj.getElementsByTagName("a");
				for(var i = 0; i < panElm.length; i++){
					var cateDir = []; 
					var cateAray = [];
					cateDir = new String(panElm[level]);
					cateDir = cateDir.replace(thisDomain + navi_dirPath,"");
					cateDir = cateDir.replace(/https?:\/\//,"");
					cateDir = cateDir.replace(thishost,"");
					cateDir = cateDir.replace(/(.*)index\..*/,"$1");
					cateAray = cateDir.split('/');
					cateDir = cateAray[level-1];
				}
				for(var j = 0; j < gnElm.length; j++){
					var linkDir = [];
					var linkAray = [];
					var linkPath = new String(gnElm.item(j));
					linkPath = linkPath.replace(/(.*)index\..*/,"$1");
					//
					var linkPath2 = linkPath.replace(thisDomain,"");
					linkPath2 = linkPath2.replace(/(.*)index\..*/,"$1");
					//
					var cateID = linkPath.replace(thisDomain + navi_dirPath,"");
					cateID = cateID.replace(/(.*)index\..*/,"$1");
					linkAray = cateID.split('/');
					cateID = linkAray[level-1];
					linkDir[j] = cateID;
				
					if(thisPath==linkPath2){
						gnElm2[j].src = gnElm2[j].src.replace("_off","_on");
						break;
					}
					if(cateDir && linkDir[j] && linkDir[j] == cateDir){
						gnElm2[j].src = gnElm2[j].src.replace("_off","_on");
						break;
					}
				}
			}else{
				gnElm2[0].src = gnElm2[0].src.replace("_off","_on");
			}
		}
	}
//
}

// ロールオーバー
function smartOver01() {
	var strArray = new Array("tmp_gnavi");
	var roArea;
	for(var i=0;i<strArray.length;i++) {
		roArea = document.getElementById(strArray[i]);
		if(!roArea) continue;
		smartRollover(strArray[i]);
	}
}
function smartOver02() {
	var strArray = new Array("tmp_tab_menu");
	var roArea;
	for(var i=0;i<strArray.length;i++) {
		roArea = document.getElementById(strArray[i]);
		if(!roArea) continue;
		smartRollover(strArray[i]);
	}
}
function smartRollover(idName) {
	if(document.getElementsByTagName) {
		var images = document.getElementById(idName).getElementsByTagName("img");
		for(var i=0; i < images.length; i++) {
			if(images[i].getAttribute("src").match("_off.")) {
				var fileName = new Array(images[i].getAttribute("src").replace("_off.", "_on."));
				var preImages = new Array();
				for (var j=0; j<fileName.length; j++) {
					preImages[j] = new Image();
					preImages[j].src = fileName[j];
				}
				images[i].onmouseover = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_off.", "_on."));
				}
				images[i].onmouseout = function() {
					this.setAttribute("src", this.getAttribute("src").replace("_on.", "_off."));
				}
			}
		}
	}
}

// IE6.0の場合実行
function checkBrowser(){
	var uName = navigator.userAgent;
	if (uName.indexOf("MSIE 6.0") > -1){
		return true;
	}
	return false;
}
/*////// event ////////////////////////////////////////////////////////////////////////////*/
// onload
window.onload = function() {
	naviFun();
	smartOver01();
	smartOver02();
	loadCookie();
}
// cookieの値でonload時に実行
function loadCookie(){
	var thisFont = getCookie(textCookieName);
	document.body.style.fontSize = thisFont;
}