﻿var hideTimer = null;
var startTime = new Date();
var activeMenu = null;
var ua = navigator.userAgent.toLowerCase();
var safari = (ua.indexOf('safari/') != -1);

function rolledOut() {
    lmStartTimeout();
}

function keepActive() {
    if (hideTimer) clearTimeout(hideTimer);
}

function lmStartTimeout() {
    startTime = new Date();
    hideTimer = setTimeout("hideSubmenu()", 500);
}
function hideSubmenu() {
    if (activeMenu != null) {
        activeMenu.style.display = "none";
        showPophide();
    }
    if (hideTimer) clearTimeout(hideTimer);
}

function reallyHideSubmenu() {
    if (activeMenu != null) {
        activeMenu.style.display = "none";
        showPophide();
    }
    if (hideTimer) clearTimeout(hideTimer);
}

function showSubmenu(menuName) {
    if (activeMenu != null) {
        reallyHideSubmenu();
    }
    var item = MM_findObj(menuName);
    positionMenu(menuName, item);
    item.style.display = "block";
    activeMenu = item;
    //hidePophide();
}

function hidePophide() {
    messageBox("Hiding pophide");
    var pophide = MM_findObj("pophide");

    if (pophide != null) {
        pophide.style.display = "none";
    }
}

function showPophide() {
    messageBox("Showing pophide");
    var pophide = MM_findObj("pophide");
    if (pophide != null) {
        pophide.style.display = "none";
    }
}

function positionMenu(menuName, item) {
    //var xitem = menuName + "_pos";
    //var x = findPosX(xitem);
    //var y = findPosY(xitem);
    //y += 16;
    //if (safari) x += 20;
    //doposition(item, x, y);
}

function doposition(menu, x, y) {
    menu.style.top = y + "px";
    menu.style.left = x + "px";
}

function findRelPosX(obj) {
    var curleft = 0;
    if (obj.offsetLeft) {
        curleft += obj.offsetLeft
    }
    else if (obj.x) {
        curleft += obj.x;
    }
    return curleft;
}

function findRelPosY(obj) {
    var curtop = 0;
    if (obj.offsetTop) {
        curtop += obj.offsetTop

    }
    else if (obj.y) {
        curtop += obj.y;
    }
    return curtop;
}

function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curleft += obj.offsetLeft
            obj = obj.offsetParent;
        }
    }
    else if (obj.x) {
        curleft += obj.x;
    }
    return curleft;
}

function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (obj.offsetParent) {
            curtop += obj.offsetTop
            obj = obj.offsetParent;
        }
    }
    else if (obj.y) {
        curtop += obj.y;
    }
    return curtop;
}

function messageBox(mess) {
    var debugarea = MM_findObj("debug");
    if (debugarea) {
        //debugarea.innerHTML = mess;
    }
}

function showShareMenu() {
    var share = MM_findObj("share");
    if (share) {
        if (share.style) {
            share.style.height = "97px";
            share.style.width = "90px";
            share.style.border = "1px solid #eeeeee";
        }
    }
}

function hideShareMenu() {
    var share = MM_findObj("share");
    if (share) {
        if (share.style) {
            share.style.height = "21px";
            share.style.width = "80px";
            share.style.border = "1px solid white";
        }
    }
}

function showFollowMenu() {
    var share = MM_findObj("follow");
    if (share) {
        if (share.style) {
            share.style.height = "86px";
            share.style.border = "1px solid #eeeeee";
        }
    }
}

function hideFollowMenu() {
    var share = MM_findObj("follow");
    if (share) {
        if (share.style) {
            share.style.height = "21px";
            share.style.border = "1px solid white";
        }
    }
}

function hideEditor(itemName) {
    var editorDiv = MM_findObj(itemName);
    if (editorDiv) {
        editorDiv.style.width = "16px";
        editorDiv.style.height = "16px";
        editorDiv.style.border = "none";
        editorDiv.style.backgroundColor = "transparent";
    }
    return false;
}

function showEditor(itemName) {
    var editorDiv = MM_findObj(itemName);
    if (editorDiv) {
        editorDiv.style.width = "auto";
        editorDiv.style.height = "auto";
        editorDiv.style.border = "1px solid #666666";
        editorDiv.style.backgroundColor = "#eeeeee";
    }
    return false;
}