var allLoaded = false;
var entry = new Array( );

function init( )
{
    if(versionCheck( ))
    {
        entry[0] = new SubMenu("layermenu01", 112, 70);
        entry[1] = new SubMenu("layermenu02", 223, 70);
        entry[2] = new SubMenu("layermenu03", 334, 70);
        entry[3] = new SubMenu("layermenu04", 446, 70);
        entry[4] = new SubMenu("layermenu05", 557, 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;

        while(tmp.className != 'layerMenu')
        {
            tmp = tmp.parentElement;
            if(tmp == null)
            {
                break;
            }
        }
        if(tmp != null)
        {
            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;
