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, 2000);
}
//以下中身
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, '#ffffff');
}
function unselectItem(sender) {
	changeCol(sender.id, '#eeeeee');
}
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, 800)" style="width:' + m.mw + 'px;">');
		document.write('<div class="menuInnerBox" onmouseover="canselHideMenu(' + "'" + m.label + "'" + ')">');
		document.write('<div style="padding-bottom: 1px;">');
		for(j = 0; j < m.items.length; j++) {
			document.write('<div style="padding-top: 1px;">');
			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: #b48271;');
	document.write('	x-index: 3;');
	document.write('}');
	document.write('div.menuInnerBox {');
	document.write('	background-color: #b48271;');
	document.write('	color: #660000;');
	document.write('	margin-left: 1px;');
	document.write('	margin-right: 1px;');

	document.write('	font-family: MS UI Gothic, Osaka;');
	document.write('	font-weight: plain;');
	document.write('	font-size: 12px;');
	document.write('	fontSize: 12px;');
	document.write('}');
	document.write('div.menuItem {');
	document.write('	background-color: #efefef;');
	document.write('	padding-left: 8px;');
	document.write('	padding-top: 2px;');
	document.write('	cursor: pointer;');
	document.write('}');
	document.write('--></style>');
}
//NN4 は古いスクリプトに丸投げする
if(!document.getElementById && !document.all && document.layers) {
	document.write('<script src="/js/menuNN4.js"></script>');
}
