﻿
var allLoaded = false ;

var entry = new Array( ) ;

var preObj = null ;

function lmInit( )
{
	if ( versionCheck( ) )
	{
		SubMenu.DELAY = 0 ; //ロールアウトから消えるまでの時間（秒）
		SubMenu.action = null ;

		// ■第一レベルのメニュー
		// new SubMenu( レイヤー名, X座標, Y座標, 'イメージ名' ) ;
		entry[ 0 ] = new SubMenu( "layermenu01", 181, 49, 'm01' ) ;

		entry[ 1 ] = new SubMenu( "layermenu02", 226, 49, 'm02' ) ;
		entry[ 2 ] = new SubMenu( "layermenu03", 281, 49, 'm03' ) ;

		entry[ 3 ] = new SubMenu( "layermenu04", 365, 49, 'm04' ) ;
		entry[ 4 ] = new SubMenu( "layermenu05", 472, 49, 'm05' ) ;
		entry[ 5 ] = new SubMenu( "layermenu06", 529, 49, 'm06' ) ;

		allLoaded = true ;

		for ( var i=0; i<entry.length; i++ )
		{
			entry[ i ].id.onmouseover = new Function("entry[" +i+ "].setMouseOver( true )") ;
			entry[ i ].id.onmouseout  = new Function("entry[" +i+ "].hideHandler( )") ;

			// メニューのRollOut時のパスを記憶しておく
			entry[ i ].setImgSrc( entry[ i ].getOffImg( ) ) ;
		}
	}
}

// -----------------------------------------------------------------

function versionCheck( )
{
	var flag = ( ( NN4 && getBrowserVersion( ).substr( 0, 3 ).toString( ) != '4.0' ) || NN6 || IE4 || IE5 ) ? true : false ;

	return flag ;
}

// -----------------------------------------------------------------

function process( )
{
	for ( i=0; i<entry.length; i++ )
	{
		entry[ i ].motion( ) ;
	}
}

// -----------------------------------------------------------------

function SubMenu( layerName, posiX, posiY, imgName )
{
	this.name    = layerName ;
	this.id      = refLayer( layerName ) ;
	this.imgName = imgName ;
	this.imgSrc  = null ;

	this.child = new Array( 0 ) ;

	this.mouseOverFlag = false ;

	shiftLayerTo( this.id, posiX, posiY ) ;
}

SubMenu.prototype.motion = function( )
{
	if ( !this.isMouseOver( ) )
	{
		this.hide( ) ;
	}
}

SubMenu.prototype.setImgSrc = function( imgOrder )
{
	this.imgSrc = imgOrder ;
}

SubMenu.prototype.getImgSrc = function( )
{
	return this.imgSrc ;
}

SubMenu.prototype.getImgName = function( )
{
	return this.imgName ;
}

SubMenu.prototype.getOffImg = function( )
{
	var imgName = this.getImgName( ) ;
	var imgSrc  = getImageObj( imgName ).src ;

	return imgSrc ;
}

SubMenu.prototype.swapImage = function( imgOrder )
{
	var imgName = this.getImgName( ) ;

	getImageObj( imgName ).src = imgOrder ;
}

SubMenu.prototype.swapImgRestore = function( )
{
	var imgSrc = this.getImgSrc( ) ;

	this.swapImage( imgSrc ) ;
}

SubMenu.prototype.hide = function( )
{
	this.swapImgRestore( ) ;

	this.setMouseOver( false ) ;

	hideLayer( this.id ) ;

	for ( var i=0; i<this.child.length; i++ )
	{
		this.child[ i ].hide( ) ;
	}
}

SubMenu.prototype.appendChild = appendChild_ ;
SubMenu.prototype.show = show_ ;
SubMenu.prototype.hideHandler = hideHandler_ ;
SubMenu.prototype.isMouseOver = isMouseOver_ ;
SubMenu.prototype.setMouseOver = setMouseOver_ ;
SubMenu.prototype.clearAll = clearAll_ ;
SubMenu.prototype.clearAction = clearAction_ ;

// -----------------------------------------------------------------

function SubMenu2( layerName, posiX, posiY )
{
	this.name  = layerName ;
	this.id    = refLayer( layerName ) ;

	this.child = new Array( 0 ) ;

	this.mouseOverFlag = false ;

	shiftLayerTo( this.id, posiX, posiY ) ;
}

SubMenu2.prototype.hide = function( )
{
	this.setMouseOver( false ) ;

	hideLayer( this.id ) ;

	for ( var i=0; i<this.child.length; i++ )
	{
		this.child[ i ].hide( ) ;
	}

}

SubMenu2.prototype.appendChild = appendChild_ ;
SubMenu2.prototype.show = show_ ;
SubMenu2.prototype.hideHandler = hideHandler_ ;
SubMenu2.prototype.isMouseOver = isMouseOver_ ;
SubMenu2.prototype.setMouseOver = setMouseOver_ ;
SubMenu2.prototype.clearAll = clearAll_ ;
SubMenu2.prototype.clearAction = clearAction_ ;

// -----------------------------------------------------------------

function appendChild_( obj )
{
	this.child[ this.child.length ] = obj ;
}

function show_( )
{
	this.clearAll( ) ;

	this.setMouseOver( true ) ;

	showLayer( this.id ) ;

	this.clearAction( ) ;

	process( ) ;
}

function hideHandler_( visited )
{
	// イベント発生元
	if ( this == preObj )
	{
		preObj = null ;

		return true ;
	}

	// この関数をはじめて呼び出した時
	if ( !visited )
	{
		preObj = this ;

		for ( var i=0; i<entry.length; i++ )
		{
			entry[ i ].hideHandler( true ) ;
		}
	}
	else
	{
		if ( this.child.length )
		{
			for ( var i=0; i<this.child.length; i++ )
			{
				this.child[ i ].hideHandler( true ) ;
			}
		}
	}

	this.setMouseOver( false ) ;

	this.clearAction( ) ;
	SubMenu.action = setTimeout( 'process( )', SubMenu.DELAY * 1000 ) ;
}

// イベント発生元より下を非表示にする
function clearAll_( visited )
{
	var found = false ;

	// イベント発生元
	if ( this == preObj )
	{
		preObj = null ;

		for ( var i=0; i<this.child.length; i++ )
		{
			this.child[ i ].hide( ) ;
		}

		// イベント発生元より上は表示する
		return true ;
	}

	// この関数をはじめて呼び出した時
	if ( !visited )
	{
		preObj = this ;

		for ( var i=0; i<entry.length; i++ )
		{
			entry[ i ].clearAll( true ) ;
		}
	}
	else
	{
		if ( this.child.length )
		{
			for ( var i=0; i<this.child.length; i++ )
			{
				if ( this.child[ i ].clearAll( true ) )
				{
					found = true ;
				}
				else
				{
					this.child[ i ].hide( true ) ;
				}
			}
		}
	}

	if ( found )
	{
		this.setMouseOver( true ) ;
	}

	return found ;
}

function isMouseOver_( )
{
	return this.mouseOverFlag ;
}

function setMouseOver_( value )
{
	this.clearAction( ) ;

	if ( this.mouseOverFlag != value )
	{
		this.mouseOverFlag = value ;
	}
}

function clearAction_( )
{
	if ( SubMenu.action )
	{
		clearTimeout( SubMenu.action ) ;
		SubMenu.action = null ;
	}
}



/* ------------------------------------------------
エラーを防ぐためのバッファー
------------------------------------------------ */

function funcBuffer( )
{
	var jsCode = funcBuffer.arguments ;

	if ( allLoaded && versionCheck( ) )
	{
		for ( var i=0; i<jsCode.length; i++ )
		{
			eval( jsCode[ i ] ) ;
		}
	}
}



/* ------------------------------------------------
NN4.x のリサイズに伴うバグ対応
------------------------------------------------ */
function resizeHandler( init )
{
	if ( init == true )
	{
		if ( NN4 )
		{
			oldWidth  = innerWidth ;
			oldHeight = innerHeight ;
			window.onresize  = resizeHandler ;
		}
	}
	else if ( innerWidth!=oldWidth || innerHeight!=oldHeight )
	{
		location.reload( ) ;
	}
}

resizeHandler( true ) ;
