/*
 * menuDropdown.js - implements an dropdown menu based on a HTML list
 * Author: Dave Lindquist (http://www.gazingus.org)
 */

var currentMenu;

if (!document.getElementById)
{
    document.getElementById = function() 
    { return null; }
}

function initializeMenu(menuId, actuatorId) 
{
    var menu = document.getElementById(menuId);
    var actuator = document.getElementById(actuatorId);

    if (menu == null || actuator == null) 
    {	
    	return;
    }

    actuator.showMenu = function() 
    {
        menu.style.left = this.offsetLeft + "px";
        menu.style.top = this.offsetTop + this.offsetHeight + "px";
        menu.style.visibility = "visible";
        currentMenu = menu;
    }

    actuator.activateMenu = function() 
    {
        if (currentMenu == null) 
        {
            this.showMenu();
        }
        else 
        {
            currentMenu.style.visibility = "hidden";
            this.showMenu();
    	}
    }
}


function activateMenu(code)
{
    var menu = document.getElementById(code + "Menu");
	var actuator = document.getElementById(code + "Actuator");
	
	if (menu == null || actuator == null) 
    {	
    	return;
    }
    
	if (currentMenu == null) 
    {
        showMenu(menu, actuator);
    }
    else 
    {
        currentMenu.style.visibility = "hidden";
        showMenu(menu, actuator);
    }
}

function showMenu(menu, actuator)
{
	menu.style.left = actuator.offsetLeft + "px";
    menu.style.top = actuator.offsetTop + actuator.offsetHeight + "px";
    menu.style.visibility = "visible";
    currentMenu = menu;
}

function deactivatemenu()
{
	if (currentMenu != null)
	{
		currentMenu.style.visibility = "hidden"; 
	}      
}

function initMenus()
{
	initializeMenu("productsMenu", "productsActuator");
	initializeMenu("gettoknowMenu", "gettoknowActuator");
	initializeMenu("marketingMenu", "marketingActuator");
	initializeMenu("resourceMenu", "resourceActuator");        
	initializeMenu("testimonialMenu", "testimonialActuator");        
}