var mnTimeoutConst = 1000;     // время задержки перед открытием и закрытием менюшки

var timeoutIdClose = new Array();
var timeoutIdOpen = new Array();

function preloadI() {
  var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadI.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function mnO(idNum)
{
    if ((typeof(is_IE) != "undefined") && (window.location.pathname=="/smartclip/SmartClip_Update_Zone.php")) {
        return;
    }
    if ((typeof idNum == 'object') && (idNum.constructor == Array)) {
        for (var i = 0; i < idNum.length; i++) {
            if (timeoutIdClose[idNum[i]]) {
                clearTimeout(timeoutIdClose[idNum[i]]);
                timeoutIdClose[idNum[i]] = 0;
            }
            if (document.getElementById("mn" + idNum[i])) {
                if (document.getElementById("mna" + idNum[i])) {
                    document.getElementById("mna" + idNum[i]).style.backgroundColor = "#848484";
                }
                timeoutIdOpen[idNum[i]] = setTimeout('mnOpen('+ idNum[i] + ')', mnTimeoutConst);
            }
        }
        for (var j=1; j < 1000; j++) {
            for (var k = 0; k < idNum.length; k++) {
                if (j != idNum[k]) {
                    if (timeoutIdClose[j]) {
                        clearTimeout(timeoutIdOpen[j]);
                        timeoutIdOpen[j] = 0;
                    }
                }
            }
        }
    }
    else {
        if (timeoutIdClose[idNum]) {
            clearTimeout(timeoutIdClose[idNum]);
            timeoutIdClose[idNum] = 0;
        }
        for (var j=1; j < 1000; j++) {
            if (j != idNum) {
                if (timeoutIdClose[j]) {
                    clearTimeout(timeoutIdOpen[j]);
                    timeoutIdOpen[j] = 0;
                }
            }
        }
        if (document.getElementById("mn" + idNum)) {
            if (document.getElementById("mna" + idNum)) {
                document.getElementById("mna" + idNum).style.backgroundColor = "#848484";
            }
            timeoutIdOpen[idNum] = setTimeout('mnOpen('+ idNum + ')', mnTimeoutConst);
        }
    }
}
function mnOpen(idNum)
{
    document.getElementById("mn" + idNum).style.display = "block";

    if (typeof(is_IE) != "undefined") {
        var aElement = document.getElementById("mn" + idNum);
        var aClientX = 0;
        var aClientY = 0;

        while (aElement){

            if (aElement.style) {
                if (aElement.style.position == "relative") {
                    break;
                }
            }

            aClientX = aClientX + aElement.offsetLeft;
            aClientY = aClientY + aElement.offsetTop;
            aElement = aElement.offsetParent;
        }

        var mnFrame = document.getElementById("mnFrame")
        var iframe = document.createElement('iframe');
        iframe.frameborder = "0";
        iframe.id = "mnFrame" + idNum;
        mnFrame.appendChild(iframe)

        document.getElementById("mnFrame" + idNum).style.left = aClientX+2;
        document.getElementById("mnFrame" + idNum).style.top = aClientY+2;

        document.getElementById("mnFrame" + idNum).style.width = document.getElementById("mn" + idNum).clientWidth+1+"px";
        document.getElementById("mnFrame" + idNum).style.height = document.getElementById("mn" + idNum).clientHeight+1+"px";
        document.getElementById("mnFrame" + idNum).style.display = "block";
    }
}

function mnC(idNum)
{
    if ((typeof(is_IE) != "undefined") && (window.location.pathname=="/smartclip/SmartClip_Update_Zone.php")) {
        return;
    }
    if ((typeof idNum == 'object') && (idNum.constructor == Array)) {
        idNum = idNum.sort(function (a,b) { return b-a; });
        for (var i = 0; i < idNum.length; i++) {
            if (document.getElementById("mn" + idNum[i])) {
                if (document.getElementById("mna" + idNum[i])) {
                    if (document.getElementById("mna" + idNum[i]).className == "rootl") {
                        document.getElementById("mna" + idNum[i]).style.backgroundColor = "#dcdcdc";
                    }
                    else {
                        document.getElementById("mna" + idNum[i]).style.backgroundColor = "#e5e5e5";
                    }
                }
                timeoutIdClose[idNum[i]] = setTimeout('mnClose('+ idNum[i] + ')', mnTimeoutConst);
            }
        }
    }
    else {
        if (document.getElementById("mn" + idNum)) {
            if (document.getElementById("mna" + idNum)) {
                if (document.getElementById("mna" + idNum).className == "rootl") {
                    document.getElementById("mna" + idNum).style.backgroundColor = "#dcdcdc";
                }
                else {
                    document.getElementById("mna" + idNum).style.backgroundColor = "#e5e5e5";
                }
            }
            timeoutIdClose[idNum] = setTimeout('mnClose('+ idNum + ')', mnTimeoutConst);
        }
    }
}

function mnClose(idNum)
{
    document.getElementById("mn" + idNum).style.display = "none";
    if (typeof(is_IE) != "undefined") {
        if (document.getElementById("mnFrame" + idNum)) {
            document.getElementById("mnFrame").removeChild(document.getElementById("mnFrame" + idNum));
        }
    }
}

function fixArrowMargin()
{
    for (var i = 0; i < 1000; i++) {
        var el = document.getElementById("mna" + i);
        if (el) {
            if ((el.className == "root") || (el.className == "rootl")) {
                if (el.parentNode.clientHeight == 38) {
                    if (el.firstChild.tagName == "IMG") {
                        el.firstChild.style.marginTop = "20px";
                    }
                }
                
            }
        }
    }
}
