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.addMenuItem = addMenuItem;
	if(!window.menus) {
		window.menus = new Array();
	}
	this.label = "menuLabel" + window.menus.length;
	window.menus[window.menus.length] = this;
}
function addMenuItem(label, url) {
	this.items[this.items.length] = label;
	this.urls[this.urls.length] = url;
}
//互換性ラッパー
function FW_showMenu(objMenu, x, y) {
	var elmMenu = new getObj(objMenu.label).obj;
	showMenu(elmMenu, x, y);
}
function FW_startTimeout() {
	scheduleHideMenu(window.activeMenu.id, 1);
}
//以下中身
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) {
	clearTimeout(window.hideMenuId);
	window.hideMenuId=setTimeout('doHideMenu("'+menuid+'")', sec);
}
function doHideMenu(menuid) {
	invi(menuid, true);
}
function canselHideMenu() {
	clearTimeout(window.hideMenuId);
}
function selectItem(sender) {
	changeCol(sender.id, '#329832');
}
function unselectItem(sender) {
	changeCol(sender.id, '#66cc66');
}
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() {
	var i, j, m, mi;
	var menus = window.menus;
	for(i = 0; i < menus.length; i++) {
		m = menus[i];
		document.write('<div class="menuOuterBox" id="' + m.label + '" onmouseover="activateMenu(this)" onmouseout="scheduleHideMenu(this.id, 15)" style="width:' + m.mw + 'px;">');
		document.write('<div class="menuInnerBox" onmouseover="canselHideMenu(' + "'" + m.label + "'" + ')">');
		document.write('<div style="padding-bottom: 0px;">');
		for(j = 0; j < m.items.length; j++) {
			document.write('<div style="padding-top: 1px;">');
			
			if ( m.items[j].match( /table/i ) ) {
			document.write('<div class="menuItem" id="' + m.label + '_' + j + '" onmouseover="selectItem(this)" onmouseout="unselectItem(this)" onclick="clickItem(' + "'" + m.urls[j] + "'" + ')" style="padding-top: 1px; height: 20px;">' + m.items[j] + '</div>');
			} else {
			document.write('<div class="menuItem" id="' + m.label + '_' + j + '" onmouseover="selectItem(this)" onmouseout="unselectItem(this)" onclick="clickItem(' + "'" + m.urls[j] + "'" + ')" style="height:' + m.mih + 'px;">' + m.items[j] + '</div>');
			}

			document.write('</div>');
		}
		document.write('</div></div></div>');
	}
}
function writeMenuStyle() {
	document.write('<style><!--');
	document.write('div.menuOuterBox {');
	document.write('	position: absolute;');
	document.write('	visibility: hidden;');
	document.write('	background-color: white;');
	document.write('	FILTER: Alpha(Opacity=90, FinishOpacity=90, Style=0);');
	document.write('	x-index: 3;');
	document.write('	border: 0px;');
	document.write('}');
	document.write('div.menuInnerBox {');
	document.write('	background-color: #329832;');
	document.write('	color: white;');
	document.write('	FILTER: Alpha(Opacity=90, FinishOpacity=90, Style=0);');
	document.write('	margin: 0px;');
	document.write('	font-family: MS UI Gothic, Osaka;');
	document.write('	font-weight: plain;');
	document.write('	font-size: 13px;');
	document.write('	fontSize: 13px;');
	document.write('	border: 0px;');
	document.write('}');
	document.write('div.menuItem {');
	document.write('	background-color: #66cc66;');
	document.write('	padding-left: 9px;');
	document.write('	FILTER: Alpha(Opacity=90, FinishOpacity=90, Style=0);');
	document.write('	cursor: pointer;');
	document.write('	border: 0px;');
	document.write('}');
	document.write('--></style>');
}
//NN4 は古いスクリプトに丸投げする
if(!document.getElementById && !document.all && document.layers) {
	document.write('');
}

function GetWndSizeW(x_ofs)
{
	var nWidth;

	if (document.all)	//IE
	{
		nWidth = document.body.clientWidth;
	}
	else				//NN
	{
		nWidth = window.innerWidth;
	}
	
	nWidth = (nWidth - 756) / 2;
	if(nWidth < 0){
		return x_ofs;
	}
	nWidth = nWidth + x_ofs;
	return nWidth;
}

function GetWndSizeH()
{
	var nHeight;

	if (document.all)	//IE
	{
		nHeight = document.body.clientHeight;
	}
	else				//NN
	{
		nHeight = window.innerHeight;
	}
	return nHeight;
}
