//==== Root-Sea, Inc. JavaScript Library ====//
/*-----------------------------------------------------/
2001-2004 (C) Root-Sea, Inc. All Rights Reserved.
Author:yoshihiro fujita [last modify 2004/7/23]
/-----------------------------------------------------*/

var gUa = navigator.userAgent.toUpperCase();
var gBrw = navigator.appName.toUpperCase();
var gPlf = navigator.platform.toUpperCase();
var gVer = navigator.appVersion;
var gPlugin = navigator.plugins;

//::::Get Platform
var gWin = (gUa.indexOf("WIN", 0) != -1);
var gMacC = (gUa.indexOf("MAC", 0) != -1);
var gMacX = false;
if (gPlugin) {
	for (var p = 0; p < gPlugin.length; p++) {
		if (gMacC && (gPlugin[p].filename.indexOf("QuickTime Plugin.plugin", 0) != -1)) {
			gMacX = true;
		}
	}
}

//::::Get Browser
var gIE = (gBrw.indexOf("MICROSOFT INTERNET EXPLORER", 0) != -1);
var gNN = (gBrw.indexOf("NETSCAPE", 0) != -1);
var gGecko = (gUa.indexOf("GECKO", 0) != -1);
var gSafari = (gUa.indexOf("APPLEWEBKIT", 0) != -1);
var gOpera = (gUa.indexOf("OPERA", 0) != -1);

//::::Get Version
var gIE3 = (gVer.indexOf("MSIE 3", 0) != -1);
var gIE4 = (gVer.indexOf("MSIE 4", 0) != -1);
var gIE5 = (gVer.indexOf("MSIE 5", 0) != -1);
var gIE6 = (gVer.indexOf("MSIE 6", 0) != -1);
var gNN4 = (gNN && (gVer.indexOf("4.", 0) != -1));

/*::::==== old Google Analytics code 2009.04 ====::::
var noTrkFlg = 0;
document.write('<scr' + 'ipt src="http://www.google-analytics.com/urchin.js" type="text/javascr' + 'ipt"></scr' + 'ipt>');
*/

/*::::==== image control Begin ====::::*/
//::::Image Preload
function imagePreload() {
	if (navigator.appVersion.charAt(0) >= 3) {
		var loadImages = new Array();
		for (var i in gPreImg) {
			loadImages[i] = new Image();
			loadImages[i].src = gPreImg[i];
		}
		gPreloadFlag = "true";
	}
}


//::::1action 1image change
function changeImg1(imgName1, swpImg1, layName) {
	if (gPreloadFlag == "true") {
		if (!!layName && document.layers) {
			document.layers[layName].document.images[imgName1].src = swpImg1;
		}
		else {
//			document.images[imgName1].src = swpImg1;
		}
	}
}
/*::::==== image control End ====::::*/


/*::::==== window control Begin ====::::*/
//::::Window Open
function windowOpen(uri, winName, w, h, which, stName) {
	var stVal0, stVal1;
	var setW = parseInt(w);
	var setH = parseInt(h);
	var winStatus, winSize, winValue;
	var wOpen;

// Set Status Value(1 or 0)
	if (which == 'disp') {
		stVal0 = 0;
		stVal1 = 1;
	}
	if (which == 'del') {
		stVal0 = 1;
		stVal1 = 0;
	}

// Set default Status Value
	var directoriesVal = stVal0;
	var statusVal = stVal0;
	var scrollbarsVal = stVal0;
	var toolbarVal = stVal0;
	var locationVal = stVal0;
	var menubarVal = stVal0;
	var resizableVal = stVal0;
	stName.indexOf('directories') != -1 ? directoriesVal = stVal0 : directoriesVal = stVal1;
	stName.indexOf('status') != -1 ? statusVal = stVal0 : statusVal = stVal1;
	stName.indexOf('scrollbars') != -1 ? scrollbarsVal = stVal0 : scrollbarsVal = stVal1;
	stName.indexOf('toolbar') != -1 ? toolbarVal = stVal0 : toolbarVal = stVal1;
	stName.indexOf('location') != -1 ? locationVal = stVal0 : locationVal = stVal1;
	stName.indexOf('menubar') != -1 ? menubarVal = stVal0 : menubarVal = stVal1;
	stName.indexOf('resizable') != -1 ? resizableVal = stVal0 : resizableVal = stVal1;
	winStatus =
		'directories=' + directoriesVal +
		',status=' + statusVal +
		',scrollbars=' + scrollbarsVal +
		',toolbar=' + toolbarVal +
		',location=' + locationVal +
		',menubar=' + menubarVal +
		',resizable=' + resizableVal;

// Window width & height adjust
	if (setW + setH > 0) {
		//Status : YES
		if (statusVal == 1) {
			//IE4 for Mac
			if (gMacC  && gIE4) {
				setH += 16;
			}
		}
		//Scroll : YES
		if (scrollbarsVal == 1) {
			//IE4 for Mac
			if (gMacC  && gIE4) {
				setW -= 1;
			}
			//NN4 for Mac
			if (gMacC && gNN4) {
				setW += 15;
			}
			//IE5 for Win
			else if (gWin && (gIE4 || gIE5 || gIE6)) {
				setW += 16;
			}
		}
		//Location : YES
		if (locationVal == 1) {
			//IE4 for Mac
			if (gMacC  && gIE4) {
				setH += 24;
			}
		}
		//Menu : YES
		if (menubarVal == 1) {
			//IE4 for Mac
			if (gWin && (gIE4 || gIE5 || gIE6)) {
				setH -= 19;
			}
		}
	}

	if (h != 0) {
		winSize = 'width=' + setW;
	}
	else if (w != 0) {
		winSize = 'height' + setH;
	}
	if (w != 0 && h != 0) {
		winSize = 'width=' + setW + ',height=' + setH;
	}
	if (setW + setH > 0) {
		winValue = winStatus + ',' + winSize;
	}
	else {
		winValue = winStatus;
	}
	winOpen = window.open(uri,winName,winValue);
}


//::::Get Window Open
function isOpener(tergetWin) {
	var flag = 0;
	var ua = navigator.userAgent;
	if (!!tergetWin) {
		if (ua.indexOf('Gecko') != -1 || ua.indexOf('MSIE 4') != -1 && ua.indexOf('Win') != -1) {
			if (!tergetWin.closed) {
				flag = 1;
			}
			else {
				flag = 2;
			}
		}
		else {
			if (typeof tergetWin.document  == 'object') {
				flag = 1;
			}
			else {
				flag = 2;
			}
		}
	}
	else {
		flag = 0;
	}
	return flag;
}


//::::Disp On Parent Window
function dispParentWin(uri) {
	if (isOpener(window.opener) == 1) {
		window.opener.location.href = uri;
	}
	else {
		windowOpen(uri, 'pWin', 0, 0, 'disp', '');
	}
}


//::::Get Window Size
function getWinSize(which) {
	var size;
	if (which == "width") {
		if (document.all) {
			size = parseInt(document.body.clientWidth);
		}
		else if (document.layers) {
			size = parseInt(window.innerWidth);
		}
		else if (document.getElementById) {
			size = parseInt(window.innerWidth);
		}
	}
	else if (which == "height") {
		if (document.all) {
			size = parseInt(document.body.clientHeight);
		}
		else if (document.layers) {
			size = parseInt(window.innerHeight);
		}
		else if (document.getElementById) {
			size = parseInt(window.innerHeight);
		}
	}
	return size;
}
/*::::==== window control End ====::::*/


/*::::==== popup navigation Begin ====::::*/
var gSubMenuName = new Array('gnPower', 'gnAuto', 'gnMaterial', 'gnCompany', 'gnInvestor', 'gnContact');
var gSubMenuObj = new Array();
var gObj = null;
var gObjId = null;
var gNaviTop = 55;
var gNaviLeft;
var gNaviRight;
var gMouseX, gMouseY;
var gSubMenuObjFlag = false;

//:::: Initial Setting
function init() {

/*
// gNav Button Set Height
if (document.getElementById) {
	h = document.getElementById('gNav').offsetHeight;
	if (gWin && gIE5) {
		h = h;
	}
	else {
		h = h - 5;
	}
	document.getElementById('gnPower').style.height = h + "px";
	document.getElementById('gnAuto').style.height = h + "px";
	document.getElementById('gnMaterial').style.height = h + "px";
	document.getElementById('gnCompany').style.height = h + "px";
	document.getElementById('gnInvestor').style.height = h + "px";
	document.getElementById('gnContact').style.height = h + "px";
}
*/


// image preload
	imagePreload();

// get sub menu object & now category
	for (var i in gSubMenuName) {
// !!! Get SubMenu (sgnPower)
		gSubMenuObj['s' + gSubMenuName[i]] = getLayerObject('s' + gSubMenuName[i]);
	}

	if (document.all) {
		document.all('gNav').onmouseover = setNowSubMenuObj;
		for (var i in gSubMenuName) {
			document.all('s' + gSubMenuName[i]).onmouseover = setNowSubMenuObj;
		}
	}
	else if (document.getElementById) {

		document.getElementById('gNav').onmouseover = setNowSubMenuObj;

		document.getElementById('sgnPower').onmouseover = setNowSubMenuObj; // !!! kore nani? wasureta...

//		for (var i in gSubMenuName) {
//			document.getElementById('s' + gSubMenuName[i]).onmouseover = setNowSubMenuObj;
//		}
//		document.onmouseover = setNowSubMenuObj;
	}
	else {
		return;
	}
//	document.onmousemove = subMenuTurnOff;
	document.onclick = hideSubMenu;

// !!!
	document.getElementById("headerWrap").onmouseover = hideSubMenu;
	document.getElementById("wholeWrap").onmouseover = hideSubMenu;
// !!!

// initial position setup of sub menu
	gSubMenuObjFlag = true;
}

//:::: Get Sub Menu Object Under Selection
function setNowSubMenuObj() {
	gObj = null;
	gObjId = null;
	gObj = this;
	gObjId = this.id;
}

//:::: Sub Menu Hide Method
function subMenuTurnOff(e) {

//	alert(gObjId);

	var gMouseX = getMousePointX(e)
	var gMouseY = getMousePointY(e)
	if (!gObj) {
		return;
	}
	if (gObjId == 'gNav') {
//		gNaviBottom = gNaviTop + document.getElementById("gNavWrap").offsetHeight + 5; // 5: #subMenu Height
		gNaviBottom = gNaviTop + document.getElementById("gNavWrap").offsetHeight;
//		if (gMouseX < gNaviLeft || gMouseX > gNaviRight || gMouseY < gNaviTop || gMouseY > gNaviBottom) {
		if (gMouseX < gNaviLeft || gMouseX > gNaviRight || gMouseY < gNaviTop) {
			hideSubMenu();
		}
	}
	else {
		var left = getLayerPositionX(gObj, 'left');
		var right = getLayerPositionX(gObj, 'right');
		var bottom = getLayerPositionY(gObj, 'bottom');
		imgStr = gObjId.substr(1);
		if (gMouseX < left || gMouseX > right || gMouseY > bottom) {
			hideSubMenu();
		}
	}
}

//:::: Display Sub Menu
function dispSubMenu(naviName, gnID) {
	if (gSubMenuObjFlag) {
		hideSubMenu(gnID);
//		alert(gnID);
//		moveLayer(gSubMenuObj[naviName], eval("g" + naviName), 84);
//		moveLayer(gSubMenuObj[naviName], eval("g" + naviName), 0); // Win IE to Opera ni dake kiiteru?
		showLayer(gSubMenuObj[naviName]);
		for (var j in gSubMenuName) {
			if (gnID == gSubMenuName[j]) {
// !!! kokoni button wo on ni suru shori ireru
				changeGNBg(gnID);
				break;
			}
		}
	}
}

//:::: Hide Sub Menu
function hideSubMenu(nowID) {
	if (!nowID) {
		nowID = null;
	}
	if (gSubMenuObjFlag) {
		for (var i in gSubMenuObj) {
			hideLayer(gSubMenuObj[i]);
			gObj = null;
			gObjId = null;
		}
		for (var j in gSubMenuName) {
			if (nowID != gSubMenuName[j]) {
// !!! mouse ga hanareta toki, button wo out ni suru shori
				restoreGNBg();
			}
		}
	}
}
/*::::==== popup navigation End ====::::*/


/*::::==== layer control Begin ====::::*/
//::::Get Layer Object
function getLayerObject(layID, p_layID) {
	var i, o;
	if (document.all) {
		o = document.all[layID];
	}
	else if (document.layers) {
		if (!!p_layID) {
			o = document.layers[p_layID].document.layers[layID];
		}
		else {
			o = document.layers[layID];
		}
	}
	else if (document.getElementById) {
		o = document.getElementById(layID);
	}
	return o; // !!! SubMenu no Object sonomono ga kaeru
}

//::::Move Layer
function moveLayer(layID, mvX, mvY) {
	if (document.all) {
		layID.style.posTop = mvY;
		layID.style.posLeft = mvX;
	}
	else if (document.layers) {
		layID.moveTo(mvX, mvY);
	}
	else if (document.getElementById && !document.all) {
		layID.style.top = mvY;
		layID.style.left = mvX;
	}
}

//::::Show Layer
function showLayer(layID) {
	if (document.all || document.getElementById) {
		layID.style.visibility = "visible";
	}
	else if (document.layers) {
		layID.visibility = "show";
	}
}

//::::Hide Layer
function hideLayer(layID) {
	if (document.all || document.getElementById) {
		layID.style.visibility = "hidden";
	}
	else if (document.layers) {
		layID.visibility = "hide";
	}
}

//::::Get Layer Width,Height
function getLayerSize(layID, which) {
	var s;
	// Get Width Size
	if (which == "width") {
		if (document.all || document.getElementById) {
			if (gIE4 && gMacC) {
				s = parseInt(layID.style.pixelWidth);
			}
			else {
				s = parseInt(layID.offsetWidth);
			}
		}
		else if (document.layers) {
			s = parseInt(layID.clip.width);
		}
	}
	// Get Height Size
	if (which == "height") {
		if (document.all || document.getElementById) {
			if (gIE4 && gMacC) {
				s = parseInt(layID.style.pixelHeight);
			}
			else {
				s = parseInt(layID.offsetHeight);
			}
		}
		else if (document.layers) {
			s = parseInt(layID.clip.height);
		}
	}
	return s;
}

//::::Get Layer Position X
function getLayerPositionX(layID, which) {
	var x;
	// Get Left Position
	if (which == "left") {
		if (document.all) {
			x = parseInt(layID.style.posLeft);
		}
		else if (document.layers) {
			x = parseInt(layID.left);
		}
		else if (document.getElementById && !document.all) {
			x = parseInt(layID.style.left);
		}
	}
	// Get Right Position
	else if (which == "right") {
		if (document.all) {
			x =  parseInt(layID.style.posLeft) + getLayerSize(layID, "width");
		}
		if (document.layers) {
			x = parseInt(layID.left) + getLayerSize(layID, "width");
		}
		else if (document.getElementById && !document.all) {
			x = parseInt(layID.style.left) + getLayerSize(layID, "width");
		}
	}
	return x;
}


//::::Get Layer Position Y
function getLayerPositionY(layID, which) {
	var y;
	// Get Top Position
	if (which == "top") {
		if (document.all) {
			y = parseInt(layID.style.posTop);
		}
		else if (document.layers) {
			y = (layID.top);
		}
		else if (document.getElementById && !document.all) {
			y = parseInt(layID.style.top);
		}
	}
	// Get Bottom Position
	else if (which == "bottom") {
		if (document.all) {
			y = parseInt(layID.style.posTop) + getLayerSize(layID, "height");
		}
		else if (document.layers) {
			y = parseInt(layID.top) + getLayerSize(layID, "height");
		}
		else if (document.getElementById && !document.all) {
			y = parseInt(layID.style.top) + getLayerSize(layID, "height");
		}
	}
	return y;
}
/*::::==== layer control End ====::::*/


/*::::==== mouse control Begin ====::::*/
//::::Get Mouse Point
function getMousePointX(e) {
	var x;
	if (document.all) {
		x = document.body.scrollLeft + event.clientX;
	}
	else if (document.layers || document.getElementById) {
		x = e.pageX;
	}
	return x;
}

function getMousePointY(e) {
	var y;
	if (document.all) {
		y = document.body.scrollTop + event.clientY;
	}
	else if (document.layers || document.getElementById) {
		y = e.pageY;
	}
	return y;
}
/*::::==== mouse control End ====::::*/


//::::Products Quick Search Open
function qSearchOpen() {
	windowOpen('http://tsubakimoto.com/product/qsearch/', 'quicksearch', 665, 530, 'del', 'scrollbars_resizable');
}


//::::Access Map Open
function mapOpen(uri) {
	windowOpen(uri, 'accessmap', 660, 540, 'del', 'menubars_scrollbars');
}


//::::Press Open
function pressOpen(uri) {
	windowOpen(uri, 'press', 660, 540, 'del', 'scrollbars_resizable_menubars');
}

//::::Ndetail Open 2 for news_detail_small_window
function NdetailOpen(uri) {
	windowOpen(uri, 'ndetail', 660, 370, 'del', 'scrollbars_resizable');
}

//::::Shiwake no Tsubaki Open
function shiwakeOpen() {
	windowOpen('/matehan/classification/', 'classification', 660, 580, 'del', '');
}

//::::Close Button Change
function closeToBack() {
	if (isOpener(window.opener) == 1) {
//		document.write('<a href="javascript:window.close();"><img src="/common/b_close.gif" width="75" height="18" border="0" alt=""></a>');
		document.write('<a href="javascript:window.close()" title="Click to close this window."><img src="/common/b_close.gif" width="75" height="18" alt="Close" /></a>');
	}
	else {
		document.write('<a href="javascript:history.back();"><img src="/common/b_customback.gif" width="74" height="18" border="0" alt=""></a>');
	}
	document.write('<img src="/common/spacer.gif" width="12" height="18" alt=""><br>');
}

//::::Custom Window Header
function dispHeader() {
		document.write('<img src="/common/spacer.gif" width="12" height="56" alt="">');
	if (isOpener(window.opener) == 1) {
		document.write('<img src="/common/logo.jpg" width="328" height="56" alt="つばきWEB SITE"><br>');
	}
	else {
		document.write('<a href="/"><img src="/common/logo.jpg" width="328" height="56" border="0" alt="つばきWEB SITE"></a><br>');
	}
}


//--------------------------------- en


//:::: Change Grobal Nav Background Images
function changeGNBg(id) {
	if (document.getElementById) {
		gn = document.getElementById("gNav");

/*
	a = id.split("gn");
	b = a[1].toLowerCase();
	fName = "url(http://tsubakimoto.com/commom/gnbg_" + b + "_on.gif)";
	alert(fName);
	gn.style.backgroundImage = fName;
*/

		if (id == "gnPower") {
			gn.style.backgroundImage = "url(http://tsubakimoto.com/common/gnbg_power_on.gif)";
		}
		if (id == "gnAuto") {
			gn.style.backgroundImage = "url(http://tsubakimoto.com/common/gnbg_auto_on.gif)";
		}
		if (id == "gnMaterial") {
			gn.style.backgroundImage = "url(http://tsubakimoto.com/common/gnbg_material_on.gif)";
		}
		if (id == "gnCompany") {
			gn.style.backgroundImage = "url(http://tsubakimoto.com/common/gnbg_company_on.gif)";
		}
		if (id == "gnInvestor") {
			gn.style.backgroundImage = "url(http://tsubakimoto.com/common/gnbg_investor_on.gif)";
		}
		if (id == "gnContact") {
			gn.style.backgroundImage = "url(http://tsubakimoto.com/common/gnbg_contact_on.gif)";
		}
	}
}

function restoreGNBg() {
	if (document.getElementById) {
		gn = document.getElementById("gNav");
		bodyCls = document.getElementsByTagName("body")[0].className.split("_");
		if (bodyCls[1] == "home" || bodyCls[1] == "news" || bodyCls[1] == "search" || bodyCls[1] == "allProduct" || bodyCls[1] == "privacy" || bodyCls[1] == "sitemap" || bodyCls[1] == "use") {
			gn.style.backgroundImage = "url(http://tsubakimoto.com/common/gnbg_out.gif)";
		}
		if (bodyCls[1] == "company") {
			gn.style.backgroundImage = "url(http://tsubakimoto.com/common/gnbg_company_on.gif)";
		}
		if (bodyCls[1] == "power") {
			gn.style.backgroundImage = "url(http://tsubakimoto.com/common/gnbg_power_on.gif)";
		}
		if (bodyCls[1] == "auto") {
			gn.style.backgroundImage = "url(http://tsubakimoto.com/common/gnbg_auto_on.gif)";
		}
		if (bodyCls[1] == "material") {
			gn.style.backgroundImage = "url(http://tsubakimoto.com/common/gnbg_material_on.gif)";
		}
		if (bodyCls[1] == "contact") {
			gn.style.backgroundImage = "url(http://tsubakimoto.com/common/gnbg_contact_on.gif)";
		}
		if (bodyCls[1] == "investor") {
			gn.style.backgroundImage = "url(http://tsubakimoto.com/common/gnbg_investor_on.gif)";
		}
	}
}


