﻿// This function will parse each item in the control array.  For each control, properties will be
// created to host the URLs to the "normal" and "hovered" images.  A pointer to the "disable"
// function will also be added to each control.
function RolloverImageButton_Init()
{
    var ctl = null;
    for (var i = 0; i < RolloverImageButtonControls.length; i++)
    {
        ctl = document.getElementById( RolloverImageButtonControls[i].ID );
        if (ctl != null)
        {
            ctl.NormalImage = RolloverImageButtonControls[i].NormalImage;
            ctl.HoveredImage = RolloverImageButtonControls[i].HoveredImage;
            ctl.Enable = RolloverImageButton_Enable;
            ctl.Disable = RolloverImageButton_Disable;
            ctl.Normal = RolloverImageButton_Normal;
            ctl.Hovered = RolloverImageButton_Hovered;
        }
    }
}

// This function will locate the specified control and set the image to either the "normal" or
// "hovered" image as specified.
function RolloverImageButton_SetImage( ctl, hovered )
{
    ctl.src = hovered ? ctl.HoveredImage : ctl.NormalImage;
}

// This function will enable/disable the specified control.  The control's image will also be
// set to the "normal" image.
function RolloverImageButton_SetDisabled( id, disabled )
{
    var ctl = document.getElementById( id );
    if (ctl != null)
    {
        ctl.disabled = disabled;
        RolloverImageButton_SetImage( id, false );
    }
}

function RolloverImageButton_Enable()
{
    RolloverImageButton_SetImage( this, false );
    this.disabled = false;
}

function RolloverImageButton_Disable()
{
    RolloverImageButton_SetImage( this, false );
    this.disabled = true;
}

function RolloverImageButton_Normal()
{
    RolloverImageButton_SetImage( this, false );
}

function RolloverImageButton_Hovered()
{
    RolloverImageButton_SetImage( this, true );
}

