﻿// Purpose: functions to display top menu
// PRECONDITION:  position_elements.js is declared first

/*

Put where you want menu....

<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
  <td id="menutd_1" class="mainMenuTd"><a href="#">Home</a></td>
  <td id="menutd_2" class="mainMenuTd" onmouseover="DisplayDropdown('menutd_2',_menu2,false);"><a href="#">Link 1</a></td>
  <td id="menutd_3" class="mainMenuTd"><a href="#">Link 2</a></td>
</tr>
</table>


put at bottom of page
<div id="menuDrop" style="position: absolute; left: -1000px; top: -1000px; z-index: 500;"></div>
<div id="menuDropLeft" style="position: absolute; left: -1000px; top: -1000px; z-index: 500;"></div>
<div id="menuDropRight" style="position: absolute; left: -1000px; top: -1000px; z-index: 500;"></div>

*/
//  *****************************
//  CONFIGURE THESE:
//  *****************************
var _absTopNum = 294;     //fixed height (pixels)
var _fixedWidth = 130;    //width of dropdowns - so we can put proper mouse-out action
var _relLeft= 0;          //adjust Y position 
var _relLeftFirstLink = 2; //adjust Y position (for first link only)
var _imagePathUrl = "images";   //put absolute or relative path to "image" folder with clear.gif file in it

//customize height for diff browsers if needed
if (!document.all ) {
  //_absTopNum = _absTopNum-7;
}
if (PositionElementsBrowserDetect.browser == "Opera") {
  //_absTopNum = _absTopNum-7;
}




//  ********************************************************
//  ********************************************************
//  DO NOT CHANGE BELOW (normally):
//  ********************************************************


var _absTop = _absTopNum + "px"; //recast as string

var menuDropObj;
var menuDropObjIsNull = true;
var menuDropLeftObj;
var menuDropLeftObjIsNull = true;
var menuDropRightObj;
var menuDropRightObjIsNull = true;

function SetImagePath(imagePath) {
    _imagePathUrl = imagePath;
}

function DisplayDropdown(objId, txt, isFirstItem,relLeft) {

    LoadObjects();
    
    var posRightGhost = _fixedWidth + 15;

    if (!menuDropObjIsNull) {
        menuDropObj.className = "showme";            
        if (txt!= "") {
            var _bottom = "<div style='display:block;width:100%;position:relative;z-index:500;'>"
               + "<a href='#' onmouseover='HideDropdown();'>"
               + "<img border='0' src='"+_imagePathUrl+"/clear.gif' width='100%' height='20px' onmouseover='HideDropdown();' />"
               + "</a>"
               + "</div>";
            var _left = "<div style='display:block;width:10px;height:400px;position:relative;z-index:550;'>"
               + "<a href='#' onmouseover='HideDropdown();'>"
               + "<img border='0' src='"+_imagePathUrl+"/clear.gif' width='10px' height='100%' onmouseover='HideDropdown();' />"
               + "</a>"
               + "</div>";

                         
            if (isFirstItem) {
                SetRelativePosition("menuDrop", objId, 0, _relLeftFirstLink+relLeft);
            } else {
                SetRelativePosition("menuDrop", objId, 0, _relLeft + relLeft);
            }
            menuDropObj.style.top = _absTop;
            menuDropObj.innerHTML = txt + _bottom;

            if (!menuDropLeftObjIsNull) {
                menuDropLeftObj.className = "showme";
                menuDropRightObj.className = "showme";
                SetRelativePosition("menuDropLeft", objId, 0, _relLeft - 15 + relLeft);
                SetRelativePosition("menuDropRight", objId, 0, _relLeft + posRightGhost + relLeft);
                menuDropLeftObj.style.top = _absTop;
                menuDropRightObj.style.top = _absTop;
                menuDropLeftObj.innerHTML = _left;
                menuDropRightObj.innerHTML = _left;
            }
        } else {
            HideDropdown();
        }
    }
}

function LoadObjects() {
    if (document.getElementById) {
        if (document.getElementById("menuDrop")) {
            menuDropObj = document.getElementById("menuDrop");
            menuDropObjIsNull = false;
        }
        if (document.getElementById("menuDropLeft")) {
            menuDropLeftObj = document.getElementById("menuDropLeft");
            menuDropLeftObjIsNull = false;
        }
        if (document.getElementById("menuDropRight")) {
            menuDropRightObj = document.getElementById("menuDropRight");
            menuDropRightObjIsNull = false;
        }
    } else if (document.all) {
        if (document.all["menuDrop"]) {
            menuDropObj = document.all["menuDrop"];
            menuDropObjIsNull = false;
        }
        if (document.all["menuDropLeft"]) {
            menuDropLeftObj = document.all["menuDropLeft"];
            menuDropLeftObjIsNull = false;
        }
        if (document.all["menuDropRight"]) {
            menuDropRightObj = document.all["menuDropRight"];
            menuDropRightObjIsNull = false;
        }
    }
}


function HideDropdown() {

    LoadObjects();
    
    if (!menuDropObjIsNull) {
        menuDropObj.className = "hideme";
        menuDropObj.innerHTML = "";
        menuDropObj.style.left = "-1000px";
    }
    if (!menuDropLeftObjIsNull) {
        menuDropLeftObj.className = "hideme";
        menuDropLeftObj.innerHTML = "";
        menuDropLeftObj.style.left = "-1000px";
    }
    if (!menuDropRightObjIsNull) {
        menuDropRightObj.className = "hideme";
        menuDropRightObj.innerHTML = "";
        menuDropRightObj.style.left = "-1000px";
    }  
    
}


