// ----------- make menu file -----------------

function init()
{
	// リストの生成
	var vstep = START_POSITION_Y;
	for( var i = 0; i < mVal.length; i++ )
	{
		menuList[i] = new LayerList( mVal[i], vstep );

		vstep += menuHeight;
	}

	if( autoOpen )
		process( autoOpen );
}

function process( item )
{
	menuList[item-1].motion(item);
}

function Size( id )
{
	this.width = getLayerSize( id, "width" );
	this.height = getLayerSize( id, "height" );
}

function childMenu( parentLayerName )
{
	var childName = parentLayerName + "Child";

	this.id = refLayer( childName );

	initLayer( this.id );

	this.size = new Size( this.id );
}

function LayerList( layerName, step )
{
	this.id = refLayer( layerName );
	this.name = layerName;

	// MSIE の場合、レイヤーを初期化
	initLayer( this.id );

	showLayer( this.id );

	this.size = new Size( this.id );
	this.child = new childMenu( this.name );

	movLayerTo( this.id, START_POSITION_X, step );
	movLayerTo( this.child.id, START_POSITION_X, step + this.size.height);

	hideLayer( this.child.id );
	getDivImage( this.id, this.name+"Img" ).src = msg_close.src;
}

LayerList.prototype.motion = function( next )
{
	var targetLayer = this.id;

	if( getLayerVisibility( this.child.id ) )
	{
		hideLayer( this.child.id );

		if( preloadFlag )
		{
			getDivImage( this.id, this.name+"Img" ).src = msg_close.src;
		}

		plusListPosition = this.child.size.height;

		for( var i=next ; i<menuList.length; i++ )
		{
			menuList[i].hide();
		}
	}
	else
	{

		showLayer( this.child.id );

		if( preloadFlag )
		{
			getDivImage( this.id, this.name+"Img" ).src = msg_open.src;
		}

		plusListPosition = this.child.size.height;

		for( var i=next; i<menuList.length; i++ )
		{
			menuList[i].show();
		}
	}
}

LayerList.prototype.hide = function()
{
	movLayerBy( this.id, 0, -plusListPosition );
	movLayerBy( this.child.id, 0, -plusListPosition );
}

LayerList.prototype.show = function()
{
	movLayerBy( this.id, 0, plusListPosition );
	movLayerBy( this.child.id, 0,  plusListPosition );
}

function resizeFunc( )
{
	if ( NN4 && MAC )
	{
		location.reload( ) ;
		return false ;
	}
}


// 画像の先読み

function preloadImages( )
{
	if ( document.images )
	{
		msg_open.src = opclIMG[0];
		msg_close.src = opclIMG[1];

		preloadFlag = true;
	}
}

preloadImages();

window.onload = init;
window.onresize = resizeFunc;

