
// Geöffnete Box
var openDD = "";
var DDs = Array();
var closeTimer;



function closeDDs()
{
    for( var k in DDs )
    {
        var dd = document.getElementById(k);
        var link = document.getElementById("__nav-"+k.substr(5));
        dd.style.visibility = "hidden";
        link.style.backgroundPosition = "right top";
        openDD = "";
    }
}



function buildDropdown( array, name )
{
    var nav          = document.getElementById("navigation");
    var table        = document.getElementById("navigation_table");
    var newDropDown  = document.createElement("table");
    var tbody        = document.createElement("tbody");

    newDropDown.className = "dropDownTable";
    newDropDown.id = "__dd-"+name;
    newDropDown.style.visibility = "hidden";



    newDropDown.onmouseover = function()
    {
        if( openDD == this.id )
            clearTimeout(closeTimer);
    }

    newDropDown.onmouseout = function()
    {
        if( openDD == this.id )
            closeTimer = setTimeout( "closeDDs()", 200 );
    }



    var headTR = document.createElement("tr");
    var headTD = document.createElement("td");
        headTD.className = "dropDown_head";
        headTR.appendChild(headTD);
        tbody.appendChild(headTR);



        for( var Caption in array)
        {
            var tempTR = document.createElement("tr");
            var tempTD = document.createElement("td");
                tempTD.className = "dropDown_link";
                tempTD.innerHTML = Caption;
                tempTD.style.cursor = "pointer";
                tempTD.name = array[Caption];


                tempTD.onmouseover = function()
                {
                    this.style.backgroundPosition = "bottom";
                }

                tempTD.onmouseout = function()
                {
                    this.style.backgroundPosition = "top";
                }

                if( array[Caption] != "http://tim.aspiria.de" && array[Caption] != "http://tim.aspiria.de/index.php?Home_en-2" )
                    tempTD.onclick = function()
                    {
                        closeDDs();
                        window.location = this.name;
                    }
                else
                    tempTD.onclick = function()
                    {
                        closeDDs();
                        window.open( this.name );
                    }


                tempTR.appendChild(tempTD);
                tbody.appendChild(tempTR);
        }



    var footTR = document.createElement("tr");
    var footTD = document.createElement("td");
        footTD.className = "dropDown_foot";
        footTR.appendChild(footTD);
        tbody.appendChild(footTR);

    newDropDown.appendChild(tbody);
    nav.appendChild(newDropDown);
}



function buildNavigation()
{
    var nav    = document.getElementById("navigation");
    var table  = document.getElementById("navigation_table");
    var tr     = document.getElementById("navigation_tr");



    // --------------------------------------------------------------------------------------------
    //    Links einfügen
    // --------------------------------------------------------------------------------------------
    for( var Caption in navigation )
    {
        var newLink = document.createElement("td");
        var val = Caption;
        newLink.innerHTML = val;
        newLink.id = "__nav-"+Caption;
        newLink.name = navigation[Caption];



        if( typeof(navigation[Caption]) != "object" )
        {
            newLink.onmouseover = function()
            {
                this.style.backgroundPosition = "right bottom";
                closeDDs();
            }

            newLink.onmouseout = function()
            {
                this.style.backgroundPosition = "right top";
            }

            newLink.onclick = function()
            {
                closeDDs();
                window.location = this.name;
            }
        }
        else
        {
            buildDropdown( navigation[Caption], Caption );
            DDs["__dd-"+Caption] = 1;

            newLink.onmouseover = function()
            {
                clearTimeout(closeTimer);

                if( openDD != "__dd-"+this.id.substr(6) )
                {
                    var id = "__dd-"+this.id.substr(6);
                    closeDDs();
                    document.getElementById(id).style.visibility = "visible";
                    this.style.backgroundPosition = "right bottom";
                    openDD = id;
                }
            }

            newLink.onmouseout = function()
            {
                var id = "__dd-"+this.id.substr(6);

                if( openDD == id )
                    closeTimer = setTimeout( "closeDDs()", 200 );
            }
        }



        tr.insertBefore( newLink, document.getElementById('lang_icons') );
    }



    var tableOffset = document.getElementById("navigation_table").offsetLeft;

    for( var Caption in navigation )
    {
        if( typeof(navigation[Caption]) == "object" )
        {
            var link = document.getElementById("__nav-"+Caption);
            var dd   = document.getElementById("__dd-"+Caption);

            dd.style.left = (link.offsetLeft+tableOffset-14)+"px";
            dd.style.top = "30px";
        }
    }
}
