// hStatusWrite.js;

// usage:         <A HREF="./" NAME="my status message">Hover over me</a>

<!-- StatusWrite handler hooks -->
hookEvent( "mouseover", "statusWrite" )
hookEvent( "mouseout", "statusCancel" )
hookEvent( "click", "changeName" )

function statusWrite( e )
{
    if ( e.element.name )
    {
        // Mouse entered anchor: display message
        window.status = "Element: " + e.element.name
    }
    else
    {
        // Mouse left anchor: remove message
        window.status = "Unknown element"
    }

    return true;
}
function statusCancel( e )
{
    window.status = "";
    return true;
}
function changeName( e )
{
    if ( e.element.name )
    {
        var oldName = e.element.name;
        fHighlightNow = false;

        if ( oldName.indexOf( "mutable" ) == -1 )
            return true;
        
        var newName = "mutable ";
        
        if ( oldName.indexOf( "highlight " ) == -1 && Math.random() 
             * 2 < 1 )
        {
            newName += "highlight ";
            fHighlightNow = true;
        }
        else
            unhighlightState( e );

        if ( oldName.indexOf( "flip " ) == -1 && Math.random() * 2 < 1 )
            newName += "flip ";
        
        // Assign new name, and display it in status bar
        e.element.name = newName;    
        statusWrite( e );
    
        // Show highlights immediately
        if ( fHighlightNow )
            highlightState( e );
    }
    return true;
}