/**
 * File.......: dhtmlMenu.js
 * Version....: $Id: dhtmlMenu.js,v 1.3 2005-01-26 10:29:39-05 andy Exp $
 * Description: Menu support routines.  Needed to hide SEO menus and to
 *              highlight the 'current' menu.
 */

var isSafari = navigator.userAgent.toLowerCase().indexOf("safari") != - 1;
var isOpera = (navigator.userAgent.indexOf('Opera') != - 1)
				|| (navigator.appName.indexOf('Opera') != - 1)
				|| (window.opera);
var isDOM = (document.getElementById ? true : false);
var isIE4 = ((document.all && ! isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);

function getRef(id)
{
    if (isDOM) {
        return document.getElementById(id);
    }

    if (isIE4) {
        return document.all[id];
    }

    if (isNS4) {
        return document.layers[id];
    }
}

/**
 *  Function.......: foldMenu
 *  Description....: Hide SEO friendly menus.  Depends on a CSS class
 *                   called 'menuHide'.
 */
function foldMenu(id)
{
    if (isSafari)
    {
        id.style.visibility = "hidden";
    } else if (isOpera)
    {
        id.style.top  = - 999;
        id.style.left = - 999;
    } else
    {
        id.attributes["class"].value = "menuHide";
    }
}

function getStyle(id)
{
    return (isNS4 ? getRef(id) : getRef(id).style);
}

/**
 *  Function.......: dhtmlRollImgSetup
 *
 *  Version History: 2001-04-02, Richard Coles, Initial Version
 *
 *  Description....: Use this function in a page body 'onLoad' event handler
 *                   to initialize variables rollover image processing via
 *                   'dhtmlRollImg'.  The document.images array is parsed.
 *                   Variables for image rollover are create for all images
 *                   with names ending in '_on', '_off', '_at' and '_over'
 *                   (Note: image name does not include the file-type; e.g.:
 *                   .gif, .jpg, etc).  Complementary images (e.g.: an '_on'
 *                   for each '_off') must exist in the same source directory.
 *
 *  Parameters.....: none
 *
 *  Return.........: none
 *
 */
function dhtmlRollImgSetup()
{
    var boolArrayDefined;
    var i;
    var result;
    var strOnImgSrc;
    var strOffImgSrc;
    var strMsg = "";
    for (i = 0; (i < document.images.length); i++)
    {
        strOnImgSrc  = "";
        strOffImgSrc = "";

        result = document.images[i].src.match(/(.+)_(on|off|over|at)\.(.+)$/i);
        if (result == null)
        {
            continue;
        } else
        {
            if (result[2] == "off" || result[2] == "on")
            {
                strOnImgSrc  = result[1] + "_on."  + result[3];
                strOffImgSrc = result[1] + "_off." + result[3];
            } else if (result[2] == "over" || result[2] == "at")
            {
                strOnImgSrc  = result[1] + "_over." + result[3];
                strOffImgSrc = result[1] + "_at."   + result[3];
            }
        }

        if ((strOnImgSrc != "") && (strOffImgSrc != "") && (document.images[i].name != ""))
        {
            eval("((typeof " + document.images[i].name + "0) == \"object\") ? boolArrayDefined = 1 : boolArrayDefined = 0;");

            //if (boolArrayDefined) continue;
            if ((document.images[i].height > 0) && (document.images[i].width > 0))
            {
                eval(document.images[i].name + "0 = new Image(document.images[i].height,document.images[i].width);");
                eval(document.images[i].name + "1 = new Image(document.images[i].height,document.images[i].width);");
            } else
            {
                eval(document.images[i].name + "0 = new Image();");
                eval(document.images[i].name + "1 = new Image();");
            }
            eval(document.images[i].name + "0.src = strOffImgSrc;");
            eval(document.images[i].name + "1.src = strOnImgSrc;");
        }
    }
}

/**
 *  Function.......: dhtmlRollImg
 *
 *  Version History: 2001-04-02, Richard Coles, Initial Version
 *
 *  Description....: Use this function in an 'onMouseOver' or 'onMouseOut'
 *                   event handler for rollover image processing.
 *
 *  Special Notes..: You must call 'imgRollSetup()' from the page body
 *                   onLoad' event for variable initialization.
 *
 *  Parameters.....: image-name: (input) 'name' value from image tag
 *                   state: (input) 1 for 'on'; 0 for 'off'
 *
 *  Returns........: void
 */

function dhtmlRollImg(strImgName, intState)
{
    var boolArrayDefined = 0;
    if (intState <= 0)
    {
        intState = 0;
    } else
    {
        intState = 1;
    }
    eval("((typeof " + strImgName + intState + ") == \"object\") ? boolArrayDefined = 1 : boolArrayDefined = 0;");
    if (! boolArrayDefined) {
        return;
    }

    eval("document.images." + strImgName + ".src = " + strImgName + intState + ".src;");
}

/**
 *  Function.......: highlightHandlerSetup
 *
 *  Description....: Does setup for highlighting of the 'on', 'off', 'at', 'over'
 *                   states and images.
 *
 *  Special Notes..: You must call 'imgRollSetup()' from the page body
 *                   onLoad' event for variable initialization.
 *
 *  Syntax.........: addHighlightHandler()
 *
 *  Parameters.....: None
 *
 *  Returns........: void
 */
function highlightHandlerSetup()
{
    if (! atmenu)
    {
        return (true);
    }

    if (typeof atmenu == "object"
            && atmenu.itemname != null && typeof document.images[atmenu.itemname] == "object"
            && document.images[atmenu.itemname].src != "")
    {
        result = document.images[atmenu.itemname].src.match(/(.+)_(on|off|over|at)\.(.+)$/i);
        document.images[atmenu.itemname].src = result[1] + "_at." + result[3];
    }

    id = getRef(atmenu.menubase + "tlm" + atmenu.itemnumber);
    if (id != null)
    {
        id.style.background = atmenu.background;
        id.style.color      = atmenu.textcolor;
    }

    id = getRef(atmenu.menubase + "tlm" + atmenu.itemnumber + "a");
    if (id != null)
    {
        id.style.background = atmenu.background;
        id.style.color      = atmenu.textcolor;
    }

    id = getRef(atmenu.menubase + "mn1" + (atmenu.itemnumber + 1));
    if (id != null)
    {
        id.style.background = atmenu.background;
        id.style.color      = atmenu.textcolor;
    }
}

/**
 *  Function.......: highlightMenu
 *
 *  Description....: Tell the system which menu should be highglighted
 *
 *  Special Notes..:
 *
 *  Parameters.....: menuBase: (input) menu's base name, usually 'm1'
 *                   itemNumber: (input) offset of the menu in menu array
 *                   fgColor: (input) preferred foreground color
 *                   bgColor: (input) preferred background color
 *                   itemName: (input) the name from which to build image files.
 *                             e.g. "products" would build products_on.gif,
 *                             products_off.gif, etc...
 *
 *  Returns........: void
 */
function highlightMenu(menuBase, itemNumber, fgColor, bgColor, itemName)
{
    atmenu            = new Object;
    atmenu.textcolor  = fgColor;
    atmenu.background = bgColor;
    atmenu.name       = menuBase + "tlm" + itemNumber;
    atmenu.menubase   = menuBase;
    atmenu.itemnumber = itemNumber;
    atmenu.itemname   = itemName;
    addLoadHandler('highlightHandlerSetup');
    addLoadHandler('dhtmlRollImgSetup');
}
