
var allLoaded = false ;

var entry = new Array( ) ;

function init( )
{
	if ( versionCheck( ) )
	{
		// Press & Event
		entry[ 0 ] = new SubMenu( "layermenu01", 0, 70 ) ;
		entry[ 1 ] = new SubMenu( "layermenu02", 108, 70 ) ;
		entry[ 2 ] = new SubMenu( "layermenu03", 216, 70 ) ;
		entry[ 3 ] = new SubMenu( "layermenu04", 324, 70 ) ;
		entry[ 4 ] = new SubMenu( "layermenu05", 432, 70 ) ;
		entry[ 5 ] = new SubMenu( "layermenu06", 540, 70 ) ;

		allLoaded = true ;
	}
}

function versionCheck( )
{
	var flag = ( ( NN4 && getBrowserVersion( ).substr( 0, 3 ).toString( ) != '4.0' ) || NN6 || IE4 || IE5 ) ? true : false ;

	return flag ;
}

function Position( x, y )
{
	this.x = ( !x ) ? 0 : x ;
	this.y = ( !y ) ? 0 : y ;
}

function SubMenu( layerName, posiX, posiY )
{
	this.name = layerName ;
	this.id   = refLayer( layerName ) ;

	this.position = new Position( posiX, posiY ) ;

	shiftLayerTo( this.id, this.getX( ), this.getY( ) ) ;
}

SubMenu.prototype.show = function( )
{
	if ( allLoaded && versionCheck( ) )
	{
		clearAll( ) ;
		showLayer( this.id ) ;
	}
}

SubMenu.prototype.hide = function( )
{

	if ( IE4 )
	{
		var tmp = event.toElement ;

		// イベント先のクラス名に [layerMenu] が含まれていない場合、レイヤーを消去する
		while ( tmp.className != 'layerMenu' )
		{
			tmp = tmp.parentElement ;
			if ( tmp == null )
			{
				break ;
			}
		}
		if ( tmp != null )
		{
			return ;
		}
	}


/*
	if ( ( IE4 || IE5 ) )
	{

		if ( event.fromElement.tagName.toUpperCase( ) == 'TD' && event.srcElement.contains( event.toElement ) ||
		    ( event.fromElement.tagName.toUpperCase( ) == 'IMG' && event.toElement.contains( event.fromElement ) ) )

		{
			return ;
		}
	}
*/
	if ( allLoaded && versionCheck( ) )
	{
		hideLayer( this.id ) ;
	}

}

SubMenu.prototype.getName = function( )
{
	return this.name ;
}

SubMenu.prototype.getX = function( )
{
	return this.position.x ;
}

SubMenu.prototype.getY = function( )
{
	return this.position.y ;
}



function funcBuffer( jsCode )
{
	if ( allLoaded && versionCheck( ) )
	{
		eval( jsCode ) ;
	}
}

function clearAll( )
{
	if ( allLoaded && versionCheck( ) )
	{
		for ( var i in entry )
		{
			hideLayer( entry[ i ].id ) ;
		}
	}
}

function resizeHandler( )
{
	if ( allLoaded && versionCheck( ) )
	{
		location.reload( ) ;
		return false ;
	}
}

function setNSEventCapture( )
{
	document.captureEvents( Event.MOUSEUP ) ;

	if ( allLoaded && versionCheck( ) )
	{
		document.captureEvents( Event.RESIZE ) ;
	}
}

if( NN4 || NN6 )
{
	setNSEventCapture( ) ;
}

document.onmouseup = clearAll ;

window.onload = init ;
window.onresize = resizeHandler ;
