/*
 * Menu Ver2.0
 */

/* Menuクラスの定義 */
function Menu( name, baselayer, topshift, leftshift, width, fontSize, fontColor, fontColorHilite, bgColor) {
	this.name			= name;		/* メニューのベースレイア名 */
	this.baselayer			= baselayer;/* メニュー表示位置の基準レイア */
	this.leftshift			= leftshift;/* 基準レイアからの相対位置左 */
	this.height			= 0;		/* メニューの高さ（フォントと連動） */
	this.width			= width;	/* メニューの横幅 */
	this.fontSize			= fontSize;		/* メニューのフォントサイズ */
	this.charPixelSize		= this.fontSize * 5;/* フォントのピクセル値 */
	this.fontColor			= fontColor;	/* 文字色 */
	this.fontColorHilite		= fontColorHilite;	/* 文字色（MouseOver時） */
	this.bgColor			= bgColor;	/* 背景色 */
	this.items			= new Array();	/* メニュー項目 */
	this.links			= new Array();	/* メニュー項目のリンク先 */
	this.target                   	= new Array();  /* ターゲット項目 */
	this.level			= new Array();  /* 0:階層表示無し 1:階層表示有り */
	this.levelMenuname		= new Array();  /* 階層表示のメニュー名 */  
	this.showflg			= false;		/* メニュー表示フラグ */
	this.subshowflg			= false;		/* サブメニュー表示フラグ */
	this.delay			= 400;	/* メニュー不可視までの遅延時間(msec) */
	this.timeOutId			= null;			/* setTimeoutのID */
	this.addMenuItem		= addMenuItem;	/* 項目追加 */
	this.hideMenu			= hideMenu;	/* メニュー不可視 */
	if(document.layers) {
		this.showMenu		= showMenuNN;	/* メニュー可視 */
		this.hideMenuDelay	= hideMenuNN;	/* メニュー不可視 */
		    this.onMenuItemOver	= onMenuItemOverNN;	/* 文字色変更（MouseOver）*/
		    this.onMenuItemOut	= onMenuItemOutNN;	/* 文字色変更（MouseOut） */
		this.writeMenu		= writeMenuNN;	/* メニュー描画 */
		this.topshift		= topshift * 0.8;	/* 基準レイアからの相対位置上 */
	}
	if(document.all) {
		this.showMenu		= showMenuIE;	/* メニュー可視 */
		this.hideMenuDelay	= hideMenuIE;	/* メニュー不可視 */
		    this.onMenuItemOver	= onMenuItemOverIE;	/* 文字色変更（MouseOver）*/
		    this.onMenuItemOut	= onMenuItemOutIE;	/* 文字色変更（MouseOut） */
		this.writeMenu		= writeMenuIE;	/* メニュー描画 */
		this.topshift		= topshift;	/* 基準レイアからの相対位置上 */
	}
}

/*
 * Netscape用メソッド群
 */

/* メニューを可視状態にする */
function showMenuNN(sm){
	if(this.timeOutId != null) {
		clearTimeout(this.timeOutId);
		this.timeOutId = null;
	}
	var menutop  = document.layers[this.baselayer].pageY + this.topshift;
	var menuleft = document.layers[this.baselayer].pageX + this.leftshift;
	eval( 'document.layers.' + this.name + '.top='  + menutop );
	eval( 'document.layers.' + this.name + '.left=' + menuleft );

	eval( 'document.layers.' + this.name + '.visibility="show"' );
	for(var i = 0; i < this.items.length; i ++ )
	{
		eval( 'document.layers.' + this.name + '.layers.' + 'item' + i +
				'.visibility="show"' );
	}
	if(sm == 1)
	{
		this.showflg = true;
		this.subshowflg = true;
	}
	else
	{
		this.showflg = true;
	}
	test();
}
/* メニューを不可視状態にする */
function hideMenuNN() {
	eval( 'document.layers.' + this.name +
			'.visibility="hide"' );
	for(var i = 0; i < this.items.length; i ++ )
	{
		eval( 'document.layers.' + this.name +
				'.layers.item' + i + '.visibility="hide"' );
		eval( 'document.layers.' + this.name +
				'.layers.selitem' + i + '.visibility="hide"' );
	}
	this.showflg = false;
	test();
}
/* 文字にMouseOver時の色を付ける */
function onMenuItemOverNN( itemindex ) {
	for(var i = 0; i < this.items.length; i ++ ) {
		if( i != itemindex ) {
			this.onMenuItemOut(i);
		}
	}
	eval( 'document.layers.' + this.name +
			'.layers.item' + itemindex + '.visibility="hide"' );
	eval( 'document.layers.' + this.name +
			'.layers.selitem' + itemindex + '.visibility="show"' );
}
/* 文字にMouseOut時の色を付ける */
function onMenuItemOutNN( itemindex ) {
	if(this.showflg){
		eval( 'document.layers.' + this.name +
				'.layers.item' + itemindex + '.visibility="show"' );
		eval( 'document.layers.' + this.name +
				'.layers.selitem' + itemindex + '.visibility="hide"' );
	}else{
		this.hideMenu(3);
	}
}
/* メニュー描画 */
function writeMenuNN(chek) {
	eval(this.name + 'object = this;');

	var content = '';
	
	if(chek == 1)
	{
	content +=
		'<LAYER ID="' + this.name + '"' +
		' top=0' +
		' width='      + this.width +
		' height='     + this.height+
		' bgColor="'   + this.bgColor + '"' +
		' visibility="hide" z-Index=1' +
		' onMouseOver="' + this.name + 'object.showMenu(1);"' +
		' onMouseOut="'  + this.name + 'object.hideMenu(1);">\n';
	}
	else
	{
	content +=
		'<LAYER ID="' + this.name + '"' +
		' top=0' +
		' width='      + this.width +
		' height='     + this.height+
		' bgColor="'   + this.bgColor + '"' +
		' visibility="hide" z-Index=1' +
		' onMouseOver="' + this.name + 'object.showMenu(0);"' +
		' onMouseOut="'  + this.name + 'object.hideMenu(0);">\n';
	}
		
	for(var i = 0,strtop = 0;
		i < this.items.length; i ++,strtop += this.charPixelSize)
	{
		if(this.level[i] == "0")
		{
			content +=

				'<LAYER ID="item' + i + '"' +
				' visibility="hide" z-Index=2' +
				' left=0' +
				' top='        + strtop     +
				' onMouseOver="' + this.name + 'object.onMenuItemOver(' + i + ');">\n' +
				'<FONT COLOR="' + this.fontColor +
				'" SIZE="' + this.fontSize + '">' +
				this.items[i] + '<BR>\n' +
				'</FONT></LAYER>\n' +
				'<LAYER ID="selitem' + i + '"' +
				' visibility="hide" z-Index=3' +
				' left=0' +
				' top='        + strtop     +
				' onMouseOut="' + this.name + 'object.onMenuItemOut(' + i + ');">\n' +
	 			'<A ' +
				' HREF="' + this.links[i] + '"'+
				' target="' + this.target[i] + '">\n' +
				'<FONT COLOR="' + this.fontColorHilite +
				'" SIZE="' + this.fontSize + '">' +
				this.items[i] + '<BR>\n' +
				'</FONT></A></LAYER>\n';
		}
		else
		{
			content +=

				'<LAYER ID="item' + i + '"' +
				' visibility="hide" z-Index=2' +
				' left=0' +
				' top='        + strtop     +
				' onMouseOver="' + this.levelMenuname[i] + '.showMenu(1); '+
				this.name + 'object.onMenuItemOver(' + i + ');">\n' +
				'<FONT COLOR="' + this.fontColor +
				'" SIZE="' + this.fontSize + '">' +
				this.items[i] + '<BR>\n' +
				'</FONT></LAYER>\n' +
				'<LAYER ID="selitem' + i + '"' +
				' visibility="hide" z-Index=3' +
				' left=0' +
				' top='        + strtop     +
				' onMouseOut="' + this.levelMenuname[i] + '.hideMenu(1); '+
				this.name + 'object.onMenuItemOut(' + i + ');">\n' +
	 			'<A ' +
				' HREF="' + this.links[i] + '">'+
				'<FONT COLOR="' + this.fontColorHilite +
				'" SIZE="' + this.fontSize + '">' +
				this.items[i] + '<BR>\n' +
				'</FONT></A></LAYER>\n';
		}
	}
	content += '</LAYER>\n';
	document.open("text/html");
	document.writeln(content);
	document.close();
}

/*
 * Internet Explorer用メソッド群
 */

/* メニューを可視状態にする */
function showMenuIE(sm){
	if(this.timeOutId != null) {
		clearTimeout(this.timeOutId);
		this.timeOutId = null;
	}
	eval( 'var menutop  = document.all.' + this.baselayer + '.offsetTop + ' + this.topshift );
	eval( 'var menuleft  = document.all.' + this.baselayer + '.offsetLeft + ' + this.leftshift );
	eval( 'document.all.' + this.name + '.style.pixelTop='  + menutop );
	eval( 'document.all.' + this.name + '.style.pixelLeft=' + menuleft );

	eval( 'document.all.' + this.name + '.style.visibility="visible"' );
	for(var i = 0; i < this.items.length; i ++ )
	{
		eval( 'document.all.' + this.name + '.document.all.' + this.name +
			'item[' + i + '].style.visibility="visible";' );
	}
	if(sm == 1)
	{
		this.showflg = true;
		this.subshowflg = true;
	}
	else
	{
		this.showflg = true;
	}
	test();
}

/* メニューを不可視状態にする */
function hideMenuIE(){
	eval( 'document.all.' + this.name +	'.style.visibility="hidden"' );
	for(var i = 0; i < this.items.length; i ++ )
	{
		eval( 'document.all.' + this.name + '.document.all.' + this.name +
			'item[' + i + '].style.visibility="hidden"' );
	}
	this.showflg = false;
	test();
}
/* 文字にMouseOver時の色を付ける */
function onMenuItemOverIE( itemindex ) {
	eval( 'document.all.' + this.name + '.document.all.' + this.name +
		'item[' + itemindex + '].style.color=this.fontColorHilite' );
}
/* 文字にMouseOut時の色を付ける */
function onMenuItemOutIE( itemindex ) {
	if(this.showflg){
		eval( 'document.all.' + this.name +	'.document.all.' + this.name +
			'item[' + itemindex + '].style.color=this.fontColor' );
	}else{
		this.hideMenu(3);
	}
}
/* メニュー描画 */
function writeMenuIE(chek) {

	eval(this.name + 'object = this;');

	var content = '';

	if(chek == 1)
	{
	content +=
		'<DIV ID="' + this.name + '"' +
		' STYLE="' +
		' position:absolute; ' +
		' top:0;' +
		' width:'            + this.width   + '; ' +
		' background-Color:' + this.bgColor + '; ' +
		' visibility:hidden; z-Index:1"' +
		' onMouseOver="' + this.name + 'object.showMenu(1);"' +
		' onMouseOut="'  + this.name + 'object.hideMenu(1);">\n';
	}
	else
	{
	content +=
		'<DIV ID="' + this.name + '"' +
		' STYLE="' +
		' position:absolute; ' +
		' top:0;' +
		' width:'            + this.width   + '; ' +
		' background-Color:' + this.bgColor + '; ' +
		' visibility:hidden; z-Index:1"' +
		' onMouseOver="' + this.name + 'object.showMenu(0);"' +
		' onMouseOut="'  + this.name + 'object.hideMenu(0);">\n';
	}
		
	for(var i = 0; i < this.items.length; i ++)
	{
		if(this.level[i] == "0")
		{
			content +=
				' <A ID="' + this.name + 'item"' +
				' STYLE="' +
				' color:'     + this.fontColor + '; ' +
				' visibility:hidden; text-decoration:none; z-Index:2"' +
				' HREF="' + this.links[i] + '"' +
				' target="' + this.target[i] + '"' +
				' onMouseOver="' + this.name + 'object.onMenuItemOver(' + i + ');"' +
				' onMouseOut="'  + this.name + 'object.onMenuItemOut(' + i + ');">\n' +
				'<FONT SIZE="' + this.fontSize + '">' +
				this.items[i] + '<BR>\n' +
				'</FONT></A>\n';
		}
		else
		{
			content +=
				' <A ID="' + this.name + 'item"' +
				' STYLE="' +
				' color:'     + this.fontColor + '; ' +
				' visibility:hidden; text-decoration:none; z-Index:2"' +
				' HREF="' + this.links[i] + '"' +
				' onMouseOver="' + this.levelMenuname[i] + '.showMenu(1); '+
				this.name + 'object.onMenuItemOver(' + i + ');"' +
				' onMouseOut="'  + this.levelMenuname[i] + '.hideMenu(1); '+
				this.name + 'object.onMenuItemOut(' + i + ');">\n' +
				'<FONT SIZE="' + this.fontSize + '">' +
				this.items[i] + '<BR>\n' +
				'</FONT></A>\n';
		}
	}
	content += '</DIV>\n';
	document.open("text/html");
	document.writeln(content);
	document.close();
}

/*
 * 共通メソッド群
 */

/* メニューを不可視状態にする（遅延時間付き） */
function hideMenu(hm) {
	if(hm == 1)
	{
		this.subshowflg = false;
	}
	if(hm == 3)
	{
		var hideObj = this.name + "object.hideMenuDelay();";
		this.timeOutId = setTimeout(hideObj,this.delay);
	}
	if(this.subshowflg)
	{
	}
	else
	{
		var hideObj = this.name + "object.hideMenuDelay();";
		this.timeOutId = setTimeout(hideObj,this.delay);
	}
}

/* 項目の追加 */
function addMenuItem(itemname,itemlink,itemtarget,levelMenuname,leve) {

	this.items[this.items.length]	= itemname;
	this.links[this.links.length]	= itemlink;
	this.target[this.target.length] = itemtarget;
	this.levelMenuname[this.levelMenuname.length] = levelMenuname;
	this.level[this.level.length]   = leve;
	this.height += this.charPixelSize;
}

/* onMouseoutでメニューを閉じる */
function out(menuname) {
	if( window.loaded ) menuname.hideMenu(0);
}

/* onMouseoverでメニューを表示する */
function on(menuname) {
	if( window.loaded ) menuname.showMenu(0);
}



function test(){
	if(this.subshowflg){
		alert('true');
	}
}