/**
 * Horizontal Menu
 * 
 * Javascript to handle horizontal menu system
 * 
 * @version		1.0rc1
 * 
 * @author		javascript-array.com
 * @copyright		Copyright 2006-2007 javascript-array.com
 */
    var timeout	= 500;
    var closetimer	= 0;
    var ddmenuitem	= null;

    var g_PopupIFrame;

    function IsIE()
    {
        return ( navigator.appName=="Microsoft Internet Explorer" );
    }

    // open hidden layer
    function mopen(id)
    {	
	    // cancel close timer
	    mcancelclosetime();

	    // close old layer
	    if(ddmenuitem)
	    {
            if (ddmenuitem.id == id)
            {
                return;
            }
	        ddmenuitem.style.visibility = 'hidden';
            if (IsIE())
            {
                if (g_PopupIFrame)
                {
                    document.body.removeChild(g_PopupIFrame);
                    g_PopupIFrame=null;
                }
            }
        }

        ddmenuitem = document.getElementById(id);
        if (ddmenuitem)
        {
            if (!IsIE())
            {
	            // get new layer and show it
	            ddmenuitem.style.visibility = 'visible';
	            return;
            }

            //Increase default zIndex of div by 1, so that DIV appears before IFrame
            ddmenuitem.style.zIndex=ddmenuitem.style.zIndex+1;

            var iFrame = document.createElement("IFRAME");
            iFrame.setAttribute("src", "");

            //Match IFrame position with divPopup
            iFrame.style.position="absolute";
            iFrame.style.left =ddmenuitem.offsetLeft + 'px';
            iFrame.style.top =ddmenuitem.offsetTop + 'px';
            iFrame.style.width =ddmenuitem.offsetWidth + 'px';
            iFrame.style.height =ddmenuitem.offsetHeight + 'px';

            document.body.appendChild(iFrame);

            //Store iFrame in global variable, so it can get removed when divPopup is hidden g_PopupIFrame=iFrame;
            g_PopupIFrame=iFrame;
            ddmenuitem.style.visibility ="visible";
        }
    }

    // close showed layer
    function mclose()
    {
	    if(ddmenuitem)
	    {
	        ddmenuitem.style.visibility = 'hidden';
	        ddmenuitem	= null;
            if (IsIE())
            {
                if (g_PopupIFrame)
                {
                    document.body.removeChild(g_PopupIFrame);
                    g_PopupIFrame=null;
                }
            }
        }
    }

    // go close timer
    function mclosetime()
    {
	    closetimer = window.setTimeout(mclose, timeout);
    }

    // cancel close timer
    function mcancelclosetime()
    {
	    if(closetimer)
	    {
		    window.clearTimeout(closetimer);
		    closetimer = null;
	    }
    }

    // close layer when click-out
    document.onclick = mclose; 
