/*
 * menuDropdown.js - implements an dropdown menu based on a HTML list
 * Author: Dave Lindquist (http://www.gazingus.org)
 */
//
// Browser Detection
//

isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
NS4 = (document.layers) ? true : false;
IEmac = ((document.all)&&(isMac)) ? true : false;
IE4plus = (document.all) ? true : false;
IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
IE6 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)) ? true : false;
IE7 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 7.")!=-1)) ? true : false;
ver4 = (NS4 || IE4plus) ? true : false;
NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;

IE5plus = IE5 || IE6;
IEMajor = 0;

if (IE4plus)
{
    var start = navigator.appVersion.indexOf("MSIE");
    var end = navigator.appVersion.indexOf(".",start);
    IEMajor = parseInt(navigator.appVersion.substring(start+5,end));
    IE5plus = (IEMajor>=5) ? true : false;
}

var ie = false;
if ((document.all)&&(navigator.appVersion.indexOf("MSIE 5")!=-1)) {
    ie = true;
    }
if ((document.all)&&(navigator.appVersion.indexOf("MSIE 6")!=-1)) {
    ie = true;
    }

var currentMenu = null;
if (!document.getElementById)
document.getElementById = function() { return null; }

function initializeMenu(menuId, actuatorId,position) {
    var menu = document.getElementById(menuId);
    var actuator = document.getElementById(actuatorId);
    if (menu == null || actuator == null) return;
    //if (window.opera) return; // I'm too tired

    actuator.onmouseover = function() {
        if (currentMenu == null) {
            this.showMenu(position);
        }
        else if(currentMenu) {
            currentMenu.style.visibility = "hidden";
            this.showMenu(position);
        }
        a=0;
        return false;
    }
    
    actuator.onmouseout = function() {
        a=1;
        setTimeout('if(a==1){currentMenu.style.visibility = "hidden"};',1000);
    }
    
    menu.onmouseover = function(){
        a=0;
    }
    
    menu.onmouseout = function() {
        a=1;
        setTimeout('if(a==1){currentMenu.style.visibility = "hidden"};',1000);
    }
    
    //~ actuator.showMenu = function(position) {
        //~ if (document.all){
            //~ menu.style.left = this.offsetLeft + 80 - position + "px";
        //~ }
        //~ else {
            //~ menu.style.left = this.offsetLeft - position + "px";
        //~ }   
        //~ menu.style.top = this.offsetTop + this.offsetHeight + 2 + "px";
        //~ menu.style.visibility = "visible";
        //~ currentMenu = menu;
    //~ }
    actuator.showMenu = function() {
        var ieto = -11;
        var ielo = 0;
        if (ie) {
            ieto = 0;
            ielo = 0;
        }
        else if (IE7){
            ieto = 0;
            ielo = 0;
        }
        menu.style.left = this.offsetLeft + ielo+ "px";
        menu.style.top = this.offsetTop + this.offsetHeight  - ieto + "px";
        menu.style.visibility = "visible";
        if (IE6){ 
            menu.style.marginLeft = "-" + actuator.offsetWidth + "px";
        }
        currentMenu = menu;
    }
}
