//---------------------------------------------------------------------------
//
// JavaScript to manipulate rollovers for maps.
//
// Rollover images are loaded on first reference and are stored in an
// associative array.
//
// Note that you must include "ClientScript.js" to use this facility.
//
//---------------------------------------------------------------------------

//
// For rollovers, we use a dynamically allocated array indexed by the
// base names of files loaded into array elements.
//
var g_area_map_rollovers;

//
// Create image arrays for rollovers. Images (other than "Empty") are
// loaded dynamically on first reference.
//
if (document.images)
{
    g_area_map_rollovers = new Array();
    g_area_map_rollovers["Empty"] = new Image();
    g_area_map_rollovers["Empty"].src = "Images/Misc/Empty.png"
}

//
// Set the image of the map (i.e., activate a rollover).
//
// This function is for internal use only. In particular, it assumes that
// 'rollovers[tag]' has been loaded and that 'document.images' has already
// been tested.
//
function SetAreaMapRollover(tag)
{
    //
    // Set the image for the *overlay* map, not the main map. The
    // rollovers might be partial images (to reduce size) and thus
    // must be backed by the full map.
    //
    // NB: The IMG element for the overlays is assumed to have the
    //     attribute "name='AreaMapRollovers'". Note that this convention
    //     allows only one image per page to have rollovers. To remove that
    //     restriction, change this and related functions to take the IMG
    //     element name as a parameter.
    //
    document["AreaMapRollovers"].src = g_area_map_rollovers[tag].src;
}

//
//
// Set the image of the map (i.e., activate a rollover).
//
function LoadAndSetAreaMapRollover(map_type, map_name, feature_name)
{
    if (document.images)
    {
        // Load image on first reference.
        if (g_area_map_rollovers[feature_name] == null)
            LoadAreaMapRollover(map_type, map_name, feature_name);

        SetAreaMapRollover(feature_name);
    }
}

//
// Reset the map to its original state.
//
function ResetAreaMapRollover()
{
    if (document.images)
        SetAreaMapRollover("Empty");
}


//
// Load a rollover for the map.
//
function LoadAreaMapRollover(map_type, map_name, feature_name)
{
    // Note assumed name and location of graphic file.
    var path = "Images/" + map_type + "/" + map_name + "/Rollovers/" + feature_name + ".png";  

    g_area_map_rollovers[feature_name] = LoadImage(path);
}
