// TEST //
GECKO = document.getElementById? 1:0 ;
NS = document.layers? 1:0 ;
IE = document.all? 1:0 ;

function haupt(untermenue)
{
var hauptmenues = new Array('ausgabe2','ausgabe3','ausgabe4','ausgabe5');

for (var menue in hauptmenues)
{
var das_menue = hauptmenues[menue];
if (GECKO) {document.getElementById(das_menue).style.display = 'none';}
else if (NS) {document.layers[das_menue].style.display = 'none';}
else if (IE) {document.all[das_menue].style.display = 'none';}
}

aufklappen(untermenue);
}

function aufklappen(untermenue)
{
if (GECKO) {document.getElementById(untermenue).style.display = 'block';}
else if (NS) {document.layers[untermenue].style.display = 'block';}
else if (IE) {document.all[untermenue].style.display = 'block';}
}

function zuklappen(untermenue)
{
if (GECKO) {document.getElementById(untermenue).style.display = 'none';}
else if (NS) {document.layers[untermenue].style.display = 'none';}
else if (IE) {document.all[untermenue].style.display = 'none';}
}

// CSS helper functions
CSS = {
    // Adds a class to an element.
    AddClass: function (e, c) {
        if (!e.className.match(new RegExp("\\b" + c + "\\b", "i")))
            e.className += (e.className ? " " : "") + c;
    },

    // Removes a class from an element.
    RemoveClass: function (e, c) {
        e.className = e.className.replace(new RegExp(" \\b" + c + "\\b|\\b" + c + "\\b ?", "gi"), "");
    }
};

// Functions for handling tabs.
Tabs = {
    // Changes to the tab with the specified ID.
    GoTo: function (inhaltId, skipReplace) {
        // This variable will be true if a tab for the specified
        // inhalt ID was found.
        var foundTab = false;

        // Get the TOC element.
        var toc = document.getElementById("toc");
        if (toc) {
            var lis = toc.getElementsByTagName("li");
            for (var j = 0; j < lis.length; j++) {
                var li = lis[j];

                // Give the current tab link the class "current" and
                // remove the class from any other TOC links.
                var anchors = li.getElementsByTagName("a");
                for (var k = 0; k < anchors.length; k++) {
                    if (anchors[k].hash == "index.php?page=rezepte#" + inhaltId) {
                        CSS.AddClass(li, "current");
                        foundTab = true;
                        break;
                    } else {
                        CSS.RemoveClass(li, "current");
                    }
                }
            }
        }

        // Show the inhalt with the specified ID.
        var divsToHide = [];
        var divs = document.getElementsByTagName("div");
        for (var i = 0; i < divs.length; i++) {
            var div = divs[i];

            if (div.className.match(/\binhalt\b/i)) {
                if (div.id == "_" + inhaltId)
                    div.style.display = "block";
                else
                    divsToHide.push(div);
            }
        }

        // Hide the other inhalt boxes.
        for (var i = 0; i < divsToHide.length; i++)
            divsToHide[i].style.display = "none";

        // Change the address bar.
        if (!skipReplace) window.location.replace("index.php?page=rezepte#" + inhaltId);
    },

    onclickHandler: function (e) {
        // Stop the event (to stop it from scrolling or
        // making an entry in the history).
        if (!e) e = window.event;
        if (e.preventDefault) e.preventDefault(); else e.returnValue = false;

        // Get the name of the anchor of the link that was clicked.
        Tabs.GoTo(this.hash.substring(1));
    },

    Init: function () {
        if (!document.getElementsByTagName) return;

        // Attach an onclick event to all the anchor links on the page.
        var anchors = document.getElementsByTagName("a");
        for (var i = 0; i < anchors.length; i++) {
            var a = anchors[i];
            if (a.hash) a.onclick = Tabs.onclickHandler;
        }

        var inhaltId;
        if (window.location.hash) inhaltId = window.location.hash.substring(1);

        var divs = document.getElementsByTagName("div");
        for (var i = 0; i < divs.length; i++) {
            var div = divs[i];

            if (div.className.match(/\binhalt\b/i)) {
                if (!inhaltId) inhaltId = div.id;
                div.id = "_" + div.id;
            }
        }

        if (inhaltId) Tabs.GoTo(inhaltId, true);
    }
};

// Hook up the OnLoad event to the tab initialization function.
window.onload = Tabs.Init;

// Hide the inhalt while waiting for the onload event to trigger.
var inhaltId = window.location.hash || "#Introduction";

if (document.createStyleSheet) {
    var style = document.createStyleSheet();
    style.addRule("div.inhalt", "display: none;");
    style.addRule("div" + inhaltId, "display: block;");
} else {
    var head = document.getElementsByTagName("head")[0];
    if (head) {
        var style = document.createElement("style");
        style.setAttribute("type", "text/css");
        style.appendChild(document.createTextNode("div.inhalt { display: none; }"));
		style.appendChild(document.createTextNode("div" + inhaltId + " { display: block; }"));
        head.appendChild(style);
    }
}
