addEvent(window, 'load', load);
var popID;
var tID;
var flash;

function load() {
    inMenu = false;
    body = document.getElementsByTagName("body")[0];
    last = null;
    var contact = new MenuP(getNode("wir"));
    var prds = new MenuP(getNode("photos"));

    contact.add(new Menu("Ulrike", "/bachmann/ulrike/index.php"));
    contact.add(new Menu("Matthias", "/bachmann/matthias/index.php"));
    contact.add(new Menu("Lea", "/bachmann/lea/index.php"));
    contact.add(new Menu("Julia", "/bachmann/julia/index.php"));
    contact.create();
    prds.add(new Menu("Nach der Geburt", "/bachmann-fotos/geburt/index.php"));
    prds.add(new Menu("Kinder zu Hause", "/bachmann-fotos/daheim/index.php"));
    prds.add(new Menu("5. bis 8. Monat", "/bachmann-fotos/5bis8Monat/index.php"));
    prds.add(new Menu("9. bis 11. Monat", "/bachmann-fotos/9bis11Monat/index.php"));
    prds.add(new Menu("12. bis 13. Monat", "/bachmann-fotos/12bis01Monat/index.php"));
    prds.add(new Menu("14. bis 15. Monat", "/bachmann-fotos/14bis15Monat/index.php"));
    prds.add(new Menu("Ostern 2007", "/bachmann-fotos/ostern/index.php"));
    prds.add(new Menu("Schwarzwald", "/bachmann-fotos/schwarzwald/index.php"));
    prds.add(new Menu("Föhr", "/bachmann-fotos/foehr/index.php"));
    prds.add(new Menu("Sylt", "/bachmann-fotos/sylt/index.php"));
    prds.add(new Menu("2.Gebrutstag", "/bachmann-fotos/geburtstag2/index.php"));
    prds.add(new Menu("Klaus und Frida", "/bachmann-fotos/klaus_frida/index.php"));
    prds.add(new Menu("Gardasee 2008", "/bachmann-fotos/gardasee/index.php"));
    prds.add(new Menu("Balaton 2008", "/bachmann-fotos/balaton/index.php"));
    prds.add(new Menu("Bayerischer Wald 2009", "/bachmann-fotos/bayerischer-wald/index.php"));
    prds.add(new Menu("Bulgarien 2009", "/bachmann-fotos/bulgarien/index.php"));
    prds.add(new Menu("Chiemsee 2010", "/bachmann-fotos/Bauernhof-am-Chiemsee/index.php"));
    prds.add(new Menu("Rotes Meer 2012", "/bachmann-fotos/rotes-meer/index.php"));
    prds.add(new Menu("Taufe", "/bachmann-fotos/taufe/index.php"));
    prds.add(new Menu("Julia", "/bachmann-fotos/julia/index.php"));
    prds.add(new Menu("Lea", "/bachmann-fotos/lea/index.php"));
    prds.add(new Menu("Urlaub", "/bachmann-fotos/urlaub/index.php"));
    prds.add(new Menu("Hochzeit", "/bachmann-fotos/hochzeit/index.php"));
    prds.create();
}

function MenuP(node) {
    this.node = node;
    this.menuItems = new Array();
    MenuP.prototype.add = function (menuItem) {
        this.menuItems[this.menuItems.length] = menuItem;
    }
    MenuP.prototype.create = function () {
        var dNode = document.createElement("div");
        dNode.className = "jsMenu";
        var str = "_" + this.node.id;
        dNode.setAttribute("id", str);
        var w = this.node.offsetWidth;
        dNode.style.width = w > 160 ? w + "px" : "160px";
        dNode.style.top = (this.node.offsetTop + this.node.offsetHeight) + "px";
        dNode.style.left = this.node.offsetLeft + "px";
        addEvent(this.node, "mouseover", function () {
            showMenuInTime(str, 150)
        });
        addEvent(this.node, "mouseout", function () {
            setInMenu(false)
        });
        dNode.setAttribute("pItemID", this.node.id);
        addEvent(dNode, "mouseover", function () {
            setInMenu(true)
        });
        addEvent(dNode, "mouseout", function () {
            setInMenu(false)
        });
        var html = "<ul>";
        for (var i = 0; i < this.menuItems.length; i++) {
            html += this.menuItems[i].getLinkHTML();
        }
        body.appendChild(dNode);
        dNode.innerHTML = html + "</ul>";
    }
}

function Menu(value, href) {
    this.value = (value == null) ? "" : value;
    this.href = (href == null) ? "" : href;
    if (this.href != "" && typeof useAbsPath != "undefined") if (useAbsPath && this.href.indexOf("http://") == -1 && this.href.indexOf("https://") == -1) this.href = "http://www.ulimatbach.de" + this.href;
    Menu.prototype.getLinkHTML = function () {
        if (this.value != "" && this.href != "") return "<li><a onclick=\"setInMenu(false); hideMenu(); return true;\" href=\"" + this.href + "\">" + this.value + "</a></li>";
        else if (this.value != "" && this.href == "") return "<li class='heading'>" + this.value + "</li>";
        else
        return "<li class='separator'>&nbsp;</li>";
    }
}

function showMenuInTime(node, time) {
    popID = setTimeout("showMenu('" + node + "')", time);
}

function showMenu(node) {
    clearTimeout(popID);
    if (typeof node == "string") node = getNode(node);
    if (last != null && last != node) hideMenu(last);
    else if (last == node) {
        setInMenu(true);
        return;
    }
    var pItem = getNode(node.getAttribute("pItemID"));
    var menuLeft = 0;
    var menuTop = pItem.offsetHeight;
    var tmp = pItem;
    while (tmp != null && tmp.tagName != "BODY") {
        if (tmp.tagName == "html:body") break;

        menuLeft += tmp.offsetLeft;
        menuTop += tmp.offsetTop;
        tmp = tmp.offsetParent;
    }
    node.style.left = menuLeft + "px";
    node.style.top = menuTop + "px";
    var w = pItem.offsetWidth;
    node.style.width = w > 160 ? w + "px" : "160px";
    node.style.display = "block";
    setInMenu(true);
    last = node;
    if (flash != null) flash.style.visibility = "hidden";
    tID = setTimeout("hideMenu( last )", 500);
}

function hideMenu(node) {
    if (node == null) {
        setInMenu(false);
        hideMenu(last);
        return;
    }
    if (typeof node == "string") node = getNode(node);
    if (!inMenu) {
        node.style.display = "none";
        var pItem = getNode(node.getAttribute("pItemID"));
        last = null;
        clearTimeout(tID);
        if (flash != null) flash.style.visibility = "visible";
    } else
    tID = setTimeout("hideMenu( last )", 500);
}

function setInMenu(value) {
    inMenu = value;
    if (!value) clearTimeout(popID);
}

function addEvent(node, evtType, func) {
    if (node.addEventListener) {
        node.addEventListener(evtType, func, false);
        return true;
    } else if (node.attachEvent) return node.attachEvent("on" + evtType, func);
    else
    return false;
}

function getNode(nodeId) {
    if (document.getElementById) return document.getElementById(nodeId);
    else if (document.all && document.all(nodeId)) return document.all(nodeId);
    else if (document.layers && document.layers[nodeId]) return document.layers[nodeId];
    else
    return false;
}

function selectNode(nodeId) {
    document.getElementById(nodeId).style.cssText = 'cursor:pointer;background-color:#4477AA;background-position:100% -36px;';
}
