﻿function __ShowAllTrail() {
    try {
        document.getElementById("BreadcrumbsDivMin").style["display"] = "none";
        document.getElementById("BreadcrumbsDivAll").style["display"] = "";
        __SetStatus("1");
    }
    catch (ex) { }
    return false;
}
function __HideTrail() {
    try {
        document.getElementById("BreadcrumbsDivMin").style["display"] = "";
        document.getElementById("BreadcrumbsDivAll").style["display"] = "none";
        __SetStatus("0");
    }
    catch (ex) { }
    return false;
}

function __SetStatus(open) {
    __CreateCookie("ScrewTurnWikiBCT", open, 365);
}
function __GetStatus() {
    var value = __ReadCookie("ScrewTurnWikiBCT");
    if (value) return value;
    else return "0";
}

function __InitBCT() {
    if (__GetStatus() == "1") {
        __ShowAllTrail();
    }
}

var __attachmentsMenuJustShown = false;
var __adminToolsMenuJustShown = false;
var __ie7Mode = false;

function __ToggleAttachmentsMenu(cx, cy) {
    var element = document.getElementById("PageAttachmentsDiv");
    if (element) {
        if (element.style["display"] == "none") {
            element.style["display"] = "";
            var pos = __AbsolutePosition(element);
            if (pos.left - cx > 0) {
                __ie7Mode = true;
                element.style["position"] = "absolute";
                element.style["top"] = cy + "px";
                element.style["left"] = (cx - pos.width) + "px";
            }
            else {
                __RepositionDiv(document.getElementById("PageAttachmentsLink"), element);
            }
            __attachmentsMenuJustShown = true;
        }
    }
    return false;
}
function __HideAttachmentsMenu() {
    var element = document.getElementById("PageAttachmentsDiv");
    if (element && !__attachmentsMenuJustShown) {
        element.style["display"] = "none";
        if (__ie7Mode) element.style["left"] = "10000px";
    }
    __attachmentsMenuJustShown = false;
    return true; // Needed to enabled next clicks' action (file download)
}

function __ToggleAdminToolsMenu(cx, cy) {
    var element = document.getElementById("AdminToolsDiv");
    if (element) {
        if (element.style["display"] == "none") {
            element.style["display"] = "";
            var pos = __AbsolutePosition(element);
            if (pos.left - cx > 0) {
                __ie7Mode = true;
                element.style["position"] = "absolute";
                element.style["top"] = cy + "px";
                element.style["left"] = (cx - pos.width) + "px";
            }
            else {
                __RepositionDiv(document.getElementById("AdminToolsLink"), element);
            }
            __adminToolsMenuJustShown = true;
        }
    }
    return false;
}
function __HideAdminToolsMenu() {
    var element = document.getElementById("AdminToolsDiv");
    if (element && !__adminToolsMenuJustShown) {
        element.style["display"] = "none";
        if (__ie7Mode) element.style["left"] = "10000px";
    }
    __adminToolsMenuJustShown = false;
    return true; // Needed to enable next clicks' action (admin tools)
}

function __HideAllMenus() {
    __HideAttachmentsMenu();
    __HideAdminToolsMenu();
}

document.body.onclick = __HideAllMenus;

function __AbsolutePosition(obj) {
    var pos = null;
    if (obj != null) {
        pos = new Object();
        pos.top = obj.offsetTop;
        pos.left = obj.offsetLeft;
        pos.width = obj.offsetWidth;
        pos.height = obj.offsetHeight;

        obj = obj.offsetParent;
        while (obj != null) {
            pos.top += obj.offsetTop;
            pos.left += obj.offsetLeft;
            obj = obj.offsetParent;
        }
    }
    return pos;
}

var __showTimer = null;
var __hideTimer = null;

function __ShowDropDown(e, divId, parent) {
    // Set a timer
    // On mouse out, cancel the timer and start a 2nd timer that hides the menu
    // When the 1st timer elapses
    //   show the drop-down
    //   on menu mouseover, cancel the 2nd timer
    //   on menu mouse out, hide the menu
    __showTimer = setTimeout('__ShowDropDownForReal(' + e.clientX + ', ' + e.clientY + ', "' + divId + '", "' + parent.id + '");', 200);
}

function __ShowDropDownForReal(cx, cy, divId, parentId) {
    var pos = __AbsolutePosition(document.getElementById(parentId));
    var menu = document.getElementById(divId);

    // This is needed to trick IE7 which, for some reason,
    // does not position the drop-down correctly with the new Default theme
    if (pos.left - cx > 30) {
        menu.style["display"] = "";
        menu.style["position"] = "absolute";
        menu.style["top"] = cy + "px";
        menu.style["left"] = (cx - 10) + "px";
    }
    else {
        menu.style["display"] = "";
        menu.style["position"] = "absolute";
        menu.style["top"] = (pos.top + pos.height) + "px";
        menu.style["left"] = pos.left + "px";
    }
    __showTimer = null;
}

function __HideDropDown(divId) {
    if (__showTimer) clearTimeout(__showTimer);
    __hideTimer = setTimeout('__HideDropDownForReal("' + divId + '");', 200);
}

function __HideDropDownForReal(divId) {
    document.getElementById(divId).style["display"] = "none";
    __hideTimer = null;
}

function __CancelHideTimer() {
    if (__hideTimer) clearTimeout(__hideTimer);
}
