// javascript Menu class
// dropdowns
// goes off at time interval, calls a callback function

var debugMenuClass = 0;

function MenuClass( timeInterval, fxnName)
    {
    this.timeInterval = timeInterval;   // milliseconds, 1000 = 1 sec

    this.fxnID = 0;
    this.fxnActive = false;
    this.fxnName = fxnName;
    this.menulist = [];

    }

MenuClass.prototype.LoadMenus = function( list)
{
    var i;
    for (i = 0; i < list.length; i++ )
        this.menulist[ i] = list[ i];
}


MenuClass.prototype.HideMenuAll = function()
{
    var d;
    var i;
    for (i = 0; i < this.menulist.length; i++ )
    {
        d = document.getElementById( this.menulist[ i]);
        if ( d) d.style.visibility = "hidden";
    }
    return( false);

    id = 'idTest';
    id = this.menulist[ 0];
    if ( d) d.style.visibility = "hidden";
    id = 'idTest2';
    id = this.menulist[ 1];
    d = document.getElementById( id);
    if ( d) d.style.visibility = "hidden";

    return( false);
}

MenuClass.prototype.EventLinkShowMenu = function( id)
{
    this.HideMenuAll();

    d = document.getElementById( id);
    if ( d) d.style.visibility = "visible";
    this.Start( 8); // or leave out for infinity

    return( false);
}

MenuClass.prototype.EventLinkHideMenu = function()
{

    this.HideMenuAll();
    this.Stop();

    return( false);
}


MenuClass.prototype.EventDivStartTimer = function()
{
    this.Stop();
    this.Start( 1);

}

MenuClass.prototype.EventDivStopTimer = function()
{
    this.Stop();

}




// start the timer
MenuClass.prototype.Start = function( time)
    {
    // make sure animation is already occuring
    if ( this.fxnID != 0)
        {
        if ( debugMenuClass)
            alert( "fxn busy");
        return;
        }

    this.timeInterval = ( time*1000);

    this.fxnID = setInterval( this.fxnName, this.timeInterval); // returns ID
    this.fxnActive = true;

    // debug
    str = 'Timer started:' + this.fxnID;
    if ( debugMenuClass)
        alert ( str);

    }

// start the timer
MenuClass.prototype.Stop = function()
    {

    if ( this.fxnActive)
        {
        clearInterval( this.fxnID);
        this.fxnID = 0;
        this.fxnActive = false;
        }

    // debug
    var str = 'Timer stopped:' + this.fxnID;
    if ( debugMenuClass)
        alert ( str);


    }

