
/* new menu code */

var currentMenu;

function toggleMenu(target)
{
	// hide active menu if any
	if(currentMenu)
		currentMenu.style.display = 'none';

	// get the element for the clicked menu-item's submenu
	currentMenu = target.firstChild.nextSibling;

	// if only having one menuitem, act as a link instead
	var items = currentMenu.getElementsByTagName('A');
	if(items.length == 1)
	{
		document.location.href = items.item(0).getAttribute('href');
		return;
	}

	// toggle clicked menu and set new activeMenu
	currentMenu.style.display = currentMenu.style.display == 'block' ? 'none' : 'block';

}

function toggleMenu(menu, show)
{
    if((show && menu.isShowing) || (!show && !menu.isShowing))
        return;

	if(show)
	{
	    // hide any showing menu
	    if(currentMenu)
	        toggleMenu(currentMenu, false);
	        
	    // set new currentMenu        
	    currentMenu = menu;
	}
	    
	// set menu visibility
	menu.style.display = show ? 'block' : 'none';
	menu.isShowing = show;
}

function getSubMenu(target)
{
    for(p = target; p; p = p.parentNode)
    {
        if(p.className && p.className == 'menuItem')
            return p.firstChild.nextSibling;
    }

    // If IE couldn't find the menuItem, try looking for menuBar, if found
    // return currentMenu
    for(p = target; p; p = p.parentNode)
    {
        if(p.id && p.id == 'divMenuBar')
            return currentMenu;
    }


    return false;
}

document.onmouseover = function(e)
{
	e = e || event;

	var menu, target = e.target || e.srcElement;

	// check if user is hovering over a main menu item
	if(menu = getSubMenu(target))
	{
	    if(!menu.parentNode.getAttribute('id'))
	    {
	        menu.parentNode.style.cursor = 'default';
	    }
	        
		// show menu
		toggleMenu(menu, true);
	}
	else if(currentMenu)
	{
	    toggleMenu(currentMenu, false);
	}
}

document.onmousedown = function(e)
{
    e = e || event;
	var target = e.target || e.srcElement;
	var subMenu = getSubMenu(target)
	if(subMenu)
	{
	    // if a lading page has been specified (through the id-attribute), open it
	    var linkTo = subMenu.parentNode.getAttribute('id')
	    if(linkTo)
	    {
	        window.location.href = '/?id=' + linkTo;
	   }
	}
}

document.onkeydown = function(e)
{
	if((e || event).keyCode == 27 && currentMenu)
	{
		currentMenu.style.display = 'none';
	}
}


function openpop(sURL,w,h) {
    window.open(sURL,'logpop','width=' + w + ', height=' + h + ', directories=no, location=no, menubar=no, scrollbars=no, scrolling=no, status=no, toolbar=no, resizable=no');
}


function init()
{
}
	
/*	
	
	var off="off";
    var on="on";
	var activeMenu;
    //('155', '115', '138', '170', '233', '282', '212', '224'); // id:s of all main folders
	
	var menusId = new Array();
	menusId["155"] = "home";
	menusId["115"] = "app_areas";
	menusId["138"] = "products";
	menusId["170"] = "antenna_basics";
	menusId["233"] = "about_us";
	menusId["282"] = "antology";
	menusId["212"] = "contact";
	menusId["224"] = "news";
	menusId["390"] = "support";

	//var menusId = new Array("115", "138", "170", "233", "282", "212", "224");
    var menus   = new Array("app_areas", "products", "antenna_basics", "about_us", "antology", "contact", "news", "support");
    
    function picswitch(obj,mode) {
		if(obj.id.substr(3) == activeMenu)
			return false;
      if(mode=="on") obj.src=obj.src.replace(".gif","_on.gif");
      else obj.src=obj.src.replace("_on.gif",".gif");
    }
    
    function closeAllMenus() {
      for(var i in menus) {
        document.getElementById(menus[i]+"dd").style.visibility="hidden";
      }
    }
    
    function handleMenus(mname) {
      var obj=document.getElementById(mname+"dd").style;
      if(obj.visibility=="visible") {
        closeAllMenus();
      } else {
        closeAllMenus();
        obj.visibility="visible";
      }
    }
    
    function gotoLink(sURL) {
      closeAllMenus();
      document.location.href="/?id=" + sURL;
    }
    
    //capture onclick and check if it was a menu that was clicked
    function bodyclick(evt) {
      var targelm=new String();
      
      if(document.all) {
        targelm=window.event.srcElement.id;
      } else {
        targelm=evt.target.id;
      }
      
      if(targelm.indexOf("mm_") != -1) {
        handleMenus(targelm.replace("mm_",""));
      } else {
        closeAllMenus();
      }
    }
        
*/