/*
** Magic-Tours drop-down menu script
** (c) by Johannes Ernesti 2006
*/

// drop-down menus
var dropDownMenus = Array(),
    dropDownLinks = Array(),
    hideTimeout = false,
    currentCategory = "";

function createMenu(category, link, items)
    {
    var m = document.createElement("a");
    m.className = container_class;
    m.setAttribute("id", "drop_" + category);
    m.category = category;
    m.onmouseover = interruptDropDownHiding;
    m.onmouseout = hideDropDownMenu;
    m.style.position = "absolute";
    m.style.display = "none";
    m.style.cursor = "pointer";
    m.length = items.length;

    if(link != "")
        document.getElementById(category).link = link;

    document.getElementById(category).onmouseover = showDropDownMenu;
    document.getElementById(category).onmouseout = hideDropDownMenu;

    for(var h1 = 0; h1 < items.length; h1++)
        {
        var item = items[h1];
        var i = document.createElement("div");
        i.className = item_class;
        i.onclick = dropDownMenuItemClick;
        if(item[0])
            id = item[0];
        else
            id = category + "/" + item[1];
        i.setAttribute("id", id);
        i.link = item[1];
        i.text = item[0];
        i.category = category;
        i.appendChild(document.createTextNode(item[0]));
        m.appendChild(i);

        if(link == "" && h1 == 0)
            document.getElementById(category).link = item[1];
        }

    document.getElementsByTagName("body")[0].appendChild(m);
    dropDownMenus.push(m);
    }

function item(text, link, id)
    {
    return Array(text, link, id);
    }


function getDropDownMenu(category)
    {
    for(var h1 = 0; h1 < dropDownMenus.length; h1++)
        {
        if(dropDownMenus[h1].category == category && dropDownMenus[h1].length > 0)
            return dropDownMenus[h1];
        }
    return false;
    }

function showDropDownMenu(category)
    {
    if(this.id)
        category = this.id;

    if(getDropDownMenu(category))
        {
        if(category == currentCategory)
            interruptDropDownHiding();
        p = getLeftBottom(category);
        s = getDropDownMenu(category).style;
        s.left = p.x + "px";
        s.top = p.y + "px";
        s.display = "block";
        currentCategory = category;

        for(var h1 = 0; h1 < dropDownMenus.length; h1++)
            {
            if(dropDownMenus[h1].category != category)
                reallyHideDropDownMenu(dropDownMenus[h1].category);
            }
        }
    else
        {
        alert("fehler");
        }
    }

function hideDropDownMenu(category)
    {
    if(this.category)
        category = this.category;
    else if(this.id)
        category = this.id;

    if(getDropDownMenu(category))
        {
        if(hideTimeout)
            window.clearTimeout(hideTimeout);
        hideTimeout = window.setTimeout("reallyHideDropDownMenu('" + category + "')", 1);
        hidingInterrupted = false;
        }
    }

function reallyHideDropDownMenu(category)
    {
    var menu = getDropDownMenu(category);
    if(menu)
        menu.style.display = "none";
    }

function interruptDropDownHiding()
    {
    if(hideTimeout)
        {
        window.clearTimeout(hideTimeout);
        hideTimeout = false;
        }
    }


// returns the position of the left down corner of the element identified with id
function getLeftBottom(id)
    {
    var e = document.getElementById(id);

    var p = new Object();
    p.x = 0;
    p.y = 0;
    p.y += e.offsetHeight;

    while(e.offsetParent != null)
        {
        p.x += e.offsetLeft;
        p.y += e.offsetTop;
        e = e.offsetParent;
        }

    return p;
    }