var DHTML = (document.getElementById || document.all || document.layers);

//コンストラクタ
function Menu(mw, mih, sel, unsel) {
	this.type = "Menu";
	this.mw = mw;
	this.mih = mih;
	this.items = new Array();
	this.urls = new Array();
	this.addMenuItem = addMenuItem;
	
	this.sel_color = sel;
	this.unsel_color = unsel;
	
	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, 800);
}
//以下中身
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) {
//	if( sender.id == 'menuLabel2_0' || sender.id == 'menuLabel2_1' || sender.id == 'menuLabel2_2' ){
//		changeCol(sender.id, "#cccccc");
//	}
//	else{
		changeCol(sender.id, "#E6E6E6");
//	}
}
function unselectItem(sender) {
//	if( sender.id == 'menuLabel2_0' || sender.id == 'menuLabel2_1' || sender.id == 'menuLabel2_2' ){
//		changeCol(sender.id, "#cccccc");
//	}
//	else{
		changeCol(sender.id, "#ffffff");
//	}
}

function clickItem(url) {
	doHideMenu(window.activeMenu.id);
	
	if( url != "" ){
		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;">');
		sel_color = m.sel_color;
		unsel_color = m.unsel_color;
		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, sel_color)" onmouseout="unselectItem(this, unsel_color)" onclick="doHideMenu(window.activeMenu.id); ' + m.urls[j] + '" style="height:' + m.mih + 'px;background-color :' + unsel_color + ';">' + 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: black;');
	document.write('	x-index: 3;');
	document.write('}');
	document.write('div.menuInnerBox {');
	document.write('	background-color: #afafaf;');
	document.write('	color: black;');
	document.write('	margin: 1px;');
	document.write('	font-family: MS UI Gothic, Osaka;');
	document.write('	font-weight: plain;');
	document.write('	font-size: 10px;');
	document.write('	fontSize: 10px;');
	document.write('}');
	document.write('div.menuItem {');
	
	
	
//	document.write('	background-color: #ffe6f9;');
	document.write('	padding-left: 1em;');
	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="pw_menuNN4.js"></script>');
}

function ChgImage( filename,target ){
	document.images[target].src = filename;
}

