//document.writeln ('<link rel="stylesheet" type="text/css" href="/navi/lib/css/common.css">');
document.writeln ('<link rel="stylesheet" type="text/css" href="/navi/lib/css/' + (bIsWin ? "win" : "mac") + "_" + (bIsIE ? "ie" : "ns") + '.css">');

		
var DHTML = (document.getElementById || document.all || document.layers);
//コンストラクタ
function Menu(mw, mih) {
	this.type = "Menu";
	this.mw = mw;
	this.mih = mih;
	this.items = new Array();
	this.urls = new Array();
	this.target = new Array();
	this.addMenuItem = addMenuItem;
	if(!window.menus) {
		window.menus = new Array();
	}
	this.label = "menuLabel" + window.menus.length;
//window.alert("label : " + this.label);
	window.menus[window.menus.length] = this;
}
function addMenuItem(label, url,target) {
	this.items[this.items.length] = label;
	this.urls[this.urls.length] = url;
	this.target[this.target.length] = target;
}
//互換性ラッパー
function FW_showMenu(objMenu, x, y) {
	var elmMenu = new getObj(objMenu.label).obj;
	showMenu(elmMenu, x, y);
}
//function FW_startTimeout(nNum) {
function FW_startTimeout(nIndex) {
//window.alert("id : " + window.menus[nIndex].label);
//	scheduleHideMenu(window.activeMenu.id, 250,nNum)
	scheduleHideMenu(window.menus[nIndex].label, 250)
}
//以下中身
function showMenu(menu, x, y) {
	if(window.activeMenu) {
		doHideMenu(window.activeMenu.id);
	}
	window.activeMenu=menu;
	invi(menu.id, false);
	move(menu.id, x, y);
}
function activateMenu(menu) {
	clearTimeout(window.hideMenuId);
	window.activeMenu=menu;
}
//function scheduleHideMenu(menuid, sec, nNum) {
function scheduleHideMenu(menuid, sec) {
	clearTimeout(window.hideMenuId);
	window.hideMenuId=setTimeout('doHideMenu("'+menuid+'")', sec);
}

function imgOut(nNum) {
	xx1 = new String("globalMenuButton0" + nNum);
	xx2 = new String("/CS/images/button_globalmenu_0"+ nNum +".gif");
	changeImage (xx1 , xx2);
}

function doHideMenu(menuid) {
	invi(menuid, true);
}
function canselHideMenu() {
	clearTimeout(window.hideMenuId);
}
function selectItem(sender) {
	changeCol(sender.id, '#FFFFAA');
}
function unselectItem(sender) {
	changeCol(sender.id, '#FFFFFF');
}
function clickItem(url) {
	doHideMenu(window.activeMenu.id);
	location.href=url;
}
//マルチブラウザ用
function getObj(name)
{
	if(document.getElementById)
	{
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	}
	else if(document.all)
	{
		this.obj = document.all[name];
		this.style = document.all[name].style;
	}
	else if(document.layers)
	{
		this.obj = getObjNN4(document,name);
		this.style = this.obj;
	}
}
function getObjNN4(obj,name)
{
	var x = obj.layers;
	var foundLayer;
	for(var i=0;i<x.length;i++)
	{
		if(x[i].id == name)
			foundLayer = x[i];
		else if(x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
		if(tmp) foundLayer = tmp;
	}
	return foundLayer;
}
function invi(id, flag)
{
	if (!DHTML) return;
	var obj = new getObj(id);
	obj.style.visibility = (flag) ? 'hidden' : 'visible';
}
function move(id, x, y)
{
	if (!DHTML) return;
	var obj = new getObj(id);
	obj.style.left = x;
	obj.style.top = y;
}
function changeCol(id, col)
{
	if (!DHTML) return;
	var obj = new getObj(id);
	obj.style.backgroundColor = col;
}
//HTML出力
function writeMenus() {
	writeMenuStyle();
	writeMenuContent();
}
function writeMenuContent() {
	if(!document.getElementById && !document.all && document.layers) {
		document.write('<!--');
	}
	
	
	var mfh;
	var li;
//	li = new Array(7);
//	li[2] = "/cgi-bin/CS/CSTOP.cgi?STID=CS0GNAVI&TRCD=TR002";
//	li[3] = "/cgi-bin/CS/CSTOP.cgi?STID=CS0GNAVI&TRCD=TR004";
//	li[4] = "/E_sell/index.html";
//	li[5] = "/E_money/index.html";
//	li[6] = "/E_parts/index.html";
//	li[7] = "/E_editorial/index.html";
//	li[8] = "http://www.carsensor.net";
	var i, j, m, mi, ii;
	var menus = window.menus;
	for(i = 0; i < menus.length; i++) {
		ii = i + 2;
		li = window.menus[i].urls[0];
		m = menus[i];
		// Resize for Mac IE 
		if(navigator.userAgent.indexOf("Mac") > -1)
		{
			mfh = m.mih + 3;
		}
		miw = m.mw - 4;        // = Left padding //
		document.write('<div style="border: 0px"  class="menuOuterBox" id="' + m.label + '" onmouseover="activateMenu(this)" border="0" onmouseout="scheduleHideMenu(this.id, 800)" style="width:' + m.mw + 'px;">');
		document.write('<a href="'+ li +'"><img src="/navi/img/button_globalmenu_0' + ii + '_m.gif" border="0" height="19"></a>');
		if(ii != "8"){
		if(ii != "4"){
		if(ii != "7"){
			document.write('<div style="border:1px;border-style:solid;width:'+ m.mw +'px;margin: 0;padding:0;background-color: #ffffff;" id="' + m.label + '">');
			for(j = 1; j < m.items.length; j++) {
//				document.write('<div border="0" class="menuItem" id="' + m.label + '_' + j + '" onmouseover="selectItem(this)" onmouseout="unselectItem(this)" style="height:' + mfh + 'px;width:'+ miw +'px;"><a href="' + m.urls[j] + '" style="height:' + mfh + 'px;text-decoration : none ;"');
				document.write('<div border="0" class="menuItem" id="' + m.label + '_' + j + '" onmouseover="selectItem(this)" onmouseout="unselectItem(this)" style="height:' + mfh + 'px;width:'+ miw +'px;"><a href="' + m.urls[j] + '" style="color:#003399;height:' + mfh + 'px;text-decoration : none ;"');
				if(m.target[j]){
					document.write(' target="_blank"');
				}
				document.write('>' + m.items[j] + '</a></div>');
				
			}
			document.write('</div>');
		}else{
			
		}
		}
		}
		document.write('</div>');
		
	}
	if(!document.getElementById && !document.all && document.layers) {
		document.write('-->');
	}
}

function writeMenuStyle() {
	document.write('<style type="text/css"><!--');
	document.write('div.menuOuterBox {');
	document.write('	position: absolute;');
	document.write('	visibility: hidden;');
	document.write('}');
	document.write('div.menuItem {');
	document.write('	background-color: #ffffff;');
	document.write('	color: #003399;');
	document.write('	padding-top: 2px;');
	document.write('	padding-left: 4px;');
	document.write('	font-size: 11px;');
	document.write('}');
	document.write('--></style>');
}

