/*
 * Menu Ver1.0
 */

/* Menuクラスの定義 */
function Menu( name, baselayer, topshift, leftshift, width ) {
	this.name				= name;		/* メニューのベースレイア名 */
	this.baselayer			= baselayer;/* メニュー表示位置の基準レイア */
	this.topshift			= topshift;	/* 基準レイアからの相対位置上 */
	this.leftshift			= leftshift;    /* 基準レイアからの相対位置左 */
	this.height				= 0;		/* メニューの高さ（フォントと連動） */
	this.width				= width;	/* メニューの横幅 */
	this.fontSize			= 3;		/* メニューのフォントサイズ */
	this.charPixelSize		= this.fontSize * 6.5;/* フォントのピクセル値 */
	this.fontColor			= "#000066";	/* 文字色 */
	this.fontColorHilite		= "#AAAA00";	/* 文字色（MouseOver時） */
	this.bgColor			= "#EEEEFF";	/* 背景色 */
	this.items				= new Array();	/* メニュー項目 */
	this.links				= new Array();	/* メニュー項目のリンク先 */
	this.showflg			= false;		/* メニュー表示フラグ */
	this.delay				= 100;	/* メニュー不可視までの遅延時間(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;	/* メニュー描画 */
	}
	if(document.all) {
		this.showMenu		= showMenuIE;	/* メニュー可視 */
		this.hideMenuDelay	= hideMenuIE;	/* メニュー不可視 */
	    this.onMenuItemOver	= onMenuItemOverIE;	/* 文字色変更（MouseOver）*/
	    this.onMenuItemOut	= onMenuItemOutIE;	/* 文字色変更（MouseOut） */
		this.writeMenu		= writeMenuIE;	/* メニュー描画 */
	}
}

/*
 * Netscape用メソッド群
 */

/* メニューを可視状態にする */
function showMenuNN(){
	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"' );
	}
	this.showflg = true;
}
/* メニューを不可視状態にする */
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;
}
/* 文字に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();
	}
}
/* メニュー描画 */
function writeMenuNN() {
	eval(this.name + 'object = this;');

	var content = '';

	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();"' +
		' onMouseOut="'  + this.name + 'object.hideMenu();">\n';
	for(var i = 0,strtop = 0;
		i < this.items.length; i ++,strtop += this.charPixelSize)
	{
		content +=

			'<LAYER ID="item' + i + '"' +
			' visibility="hide" z-Index=2' +
			' left=0' +
			' top='        + strtop     +
			' onMouseOver="' + this.name + 'object.onMenuItemOver(' + i + ');">\n' +
			'<span class="pulldm">' + /*									+by Now */
			'<FONT COLOR="' + this.fontColor +
			'" SIZE="' + this.fontSize + '">' +
			this.items[i] + '<BR>\n' +
			'</FONT></span></LAYER>\n' + /*									+by Now */
			'<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] + '">\n' +
			'<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(){
	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";' );
	}
	this.showflg = true;
}
/* メニューを不可視状態にする */
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;
}
/* 文字に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();
	}
}
/* メニュー描画 */
function writeMenuIE() {
	eval(this.name + 'object = this;');

	var content = '';

	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();"' +
		' onMouseOut="'  + this.name + 'object.hideMenu();">\n';
	for(var i = 0; i < this.items.length; i ++)
	{
		content +=
			' <A ID="' + this.name + 'item"' +
			' STYLE="' +
			' color:'     + this.fontColor + '; ' +
			' visibility:hidden; text-decoration:none; z-Index:2"' +
			' HREF="' + this.links[i] + '"' +
			' onMouseOver="' + this.name + 'object.onMenuItemOver(' + i + ');"' +
			' onMouseOut="'  + this.name + 'object.onMenuItemOut(' + i + ');">\n' +
			'<span class="pulldm">' + /*									+by Now */
			'<FONT SIZE="' + this.fontSize + '">' +
			this.items[i] + '<BR>\n' +
			'</FONT></span></A>\n'; /*									+by Now */
	}
	content += '</DIV>\n';
	document.open("text/html");
	document.writeln(content);
	document.close();
}

/*
 * 共通メソッド群
 */

/* メニューを不可視状態にする（遅延時間付き） */
function hideMenu() {
	var hideObj = this.name + "object.hideMenuDelay();";
	this.timeOutId = setTimeout(hideObj,this.delay);
}

/* 項目の追加 */
function addMenuItem(itemname,itemlink) {

	this.items[this.items.length]	= itemname;
	this.links[this.links.length]	= itemlink;
	this.height += this.charPixelSize;
}
