
if (window.pageYOffset === undefined) {
    window.getPageYOffset = function () {
        return document.documentElement.scrollTop;
    }
}
else {
    window.getPageYOffset = function () {
        return window.pageYOffset;
    }
}

function testPositionFixed () {
    var tester = $("<div style=\"position: fixed; top: 0; left: 0; height: 1px; width: 1px; overflow: hidden;\"></div>")
    $(document.body).append(tester);
    var result = (tester.position().top == getPageYOffset());
    $(document.body).remove(tester);
    return result;
}

function createMenu(lang, container, fix) {
    var items;
    switch(lang) {
        case "welcome":
            items = [
                {title: "Deutsch", href: "/de/index.htm"},
                {title: "English", href: "/en/index.htm"},
                {title: "Fran&ccedil;ais", href: "/fr/index.htm"},
                {title: "&#x0420;&#x0443;&#x0441;&#x0441;&#x043a;&#x0438;&#x0439;", href: "/ru/index.htm"},
                {title: "Impressum", href: "impressum.htm"}
            ];
            break;
        case "de":
            items = [
                {title: "Homepage", href: "index.htm"},
                {title: "Unternehmen", href: "unternehmen.htm"},
                {title: "Philosophie", href: "philo.htm"},
                {title: "Chronik", href: "chronik.htm"},
                {title: "Mattes &amp; Ammann", href: "mua.htm"},
                {title: "Zukunftsplanung", href: "zukunfts.htm"},
                {title: "T&auml;tigkeitsfeld", href: "taetig.htm"},
                {title: "Produktionsm&ouml;glichkeiten", href: "produktionsm.htm"},
                {title: "D + S-Center", href: "ds.htm"},
                {title: "Labor 1 und 2", href: "laborIuII.htm"},
                {title: "Zertifizierungen", href: "zertifizierungen.htm"},
                {title: "SA 8000", href: "sa_8000.htm"},
                {title: "Gesundheitsmanagement", href: "gesundheitsmanagement.htm"},
                {title: "Forschungsprojekte", href: "forschung.htm"},
                {title: "D + E", href: "due.htm"},
                {title: "Corporate Identity", href: "ci.htm"},
                {title: "Kulturmanagement", href: "kulturmanagement.htm"},
                {title: "Innovation", href: "patente.htm"},
                {title: "Was macht M&amp;A", href: "was_macht_mua.htm"},
                {title: "Belieferte Branchen", href: "branchen.htm"},
                {title: "Kommunikation", href: "kommunik.htm"},
                {title: "Externe Links", href: "links.htm"},
                {title: "e-mail", href: "mailto:info@mattesammann.de"}
            ];
            break;
        case "en":
            items = [
                {title: "Homepage", href: "index.htm"},
                {title: "Company", href: "unternehmen.htm"},
                {title: "Philosophy", href: "philo.htm"},
                {title: "History", href: "chronik.htm"},
                {title: "Mattes &amp; Ammann", href: "mua.htm"},
                {title: "Future", href: "zukunfts.htm"},
                {title: "Activity", href: "taetig.htm"},
                {title: "Production Facilities", href: "produktionsm.htm"},
                {title: "S + C Support", href: "ds.htm"},
                {title: "Laboratory 1 and 2", href: "laborIuII.htm"},
                {title: "Certifications", href: "zertifizierungen.htm"},
                {title: "SA 8000", href: "sa_8000.htm"},
                {title: "Health Management", href: "gesundheitsmanagement.htm"},
                {title: "Research Projects", href: "forschung.htm"},
                {title: "Design + Development", href: "due.htm"},
                {title: "Corporate Identity", href: "ci.htm"},
                {title: "Culture Management", href: "kulturmanagement.htm"},
                {title: "Innovation", href: "patente.htm"},
                {title: "What happens at M&amp;A", href: "was_macht_mua.htm"},
                {title: "Industries Supplied", href: "branchen.htm"},
                {title: "Communication", href: "kommunik.htm"},
                {title: "External Links", href: "links.htm"},
                {title: "e-mail", href: "mailto:info@mattesammann.de"}
            ];
            break;
        case "fr":
            items = [
                {title: "Homepage", href: "index.htm"},
                {title: "Soci&eacute;t&eacute;", href: "unternehmen.htm"},
                {title: "Philosophie", href: "philo.htm"},
                {title: "Chronique", href: "chronik.htm"},
                {title: "Mattes &amp; Ammann", href: "mua.htm"},
                {title: "Projects d'avenir", href: "zukunfts.htm"},
                {title: "Activit&eacute;s de production", href: "taetig.htm"},
                {title: "Outil de production", href: "produktionsm.htm"},
                {title: "Centre de service", href: "ds.htm"},
                {title: "Laboratoires 1 et 2", href: "laborIuII.htm"},
                {title: "Certifications", href: "zertifizierungen.htm"},
                {title: "SA 8000", href: "sa_8000.htm"},
                {title: "Gestion des soins de sant&eacute;", href: "gesundheitsmanagement.htm"},
                {title: "Projects de recherche", href: "forschung.htm"},
                {title: "D + E", href: "due.htm"},
                {title: "Conception et d&eacute;veloppement", href: "ci.htm"},
                {title: "Management culturel", href: "kulturmanagement.htm"},
                {title: "Innovation", href: "patente.htm"},
                {title: "Activit&eacute;s de M&amp;A", href: "was_macht_mua.htm"},
                {title: "Secteurs industriels", href: "branchen.htm"},
                {title: "Interlocuteurs", href: "kommunik.htm"},
                {title: "Liens", href: "links.htm"},
                {title: "Mel", href: "mailto:info@mattesammann.de"}
            ];
            break;
        case "ru":
            items = [
                {title: "&#x0414;&#x043e;&#x043c;&#x0430;&#x0448;&#x043d;&#x044f;&#x044f; &#x0441;&#x0442;&#x0440;&#x0430;&#x043d;&#x0438;&#x0446;&#x0430;", href: "index.htm"},
                {title: "&#x041f;&#x0440;&#x0435;&#x0434;&#x043f;&#x0440;&#x0438;&#x044f;&#x0442;&#x0438;&#x0435;", href: "unternehmen.htm"},
                {title: "&#x0424;&#x0438;&#x043b;&#x043e;&#x0441;&#x043e;&#x0444;&#x0438;&#x044f; &#x043f;&#x0440;&#x0435;&#x0434;&#x043f;&#x0440;&#x0438;&#x044f;&#x0442;&#x0438;&#x044f;", href: "philo.htm"},
                {title: "&#x0418;&#x0441;&#x0442;&#x043e;&#x0440;&#x0438;&#x044f;", href: "chronik.htm"},
                {title: "Mattes &amp; Ammann", href: "mua.htm"},
                {title: "&#x041f;&#x043b;&#x0430;&#x043d;&#x0438;&#x0440;&#x043e;&#x0432;&#x0430;&#x043d;&#x0438;&#x0435;", href: "zukunfts.htm"},
                {title: "&#x0421;&#x0444;&#x0435;&#x0440;&#x0430; &#x0434;&#x0435;&#x044f;&#x0442;&#x0435;&#x043b;&#x044c;&#x043d;&#x043e;&#x0441;&#x0442;&#x0438;", href: "taetig.htm"},
                {title: "&#x041f;&#x0440;&#x043e;&#x0438;&#x0437;&#x0432;&#x043e;&#x0434;&#x0441;&#x0442;&#x0432;&#x0435;&#x043d;&#x043d;&#x044b;&#x0435; &#x0432;&#x043e;&#x0437;&#x043c;&#x043e;&#x0436;&#x043d;&#x043e;&#x0441;&#x0442;&#x0438;", href: "produktionsm.htm"},
                {title: "&#x0421;&#x0435;&#x0440;&#x0432;&#x0438;&#x0441;&#x043d;&#x044b;&#x0439; &#x0446;&#x0435;&#x043d;&#x0442;&#x0440;", href: "ds.htm"},
                {title: "&#x041b;&#x0430;&#x0431;&#x043e;&#x0440;&#x0430;&#x0442;&#x043e;&#x0440;&#x0438;&#x044f; 1 &#x0438; 2", href: "laborIuII.htm"},
                {title: "&#x0421;&#x0435;&#x0440;&#x0442;&#x0438;&#x0444;&#x0438;&#x043a;&#x0430;&#x0442;&#x044b;", href: "zertifizierungen.htm"},
                {title: "SA 8000", href: "sa_8000.htm"},
                {title: "&#x041e;&#x0445;&#x0440;&#x0430;&#x043d;&#x0430; &#x0437;&#x0434;&#x043e;&#x0440;&#x043e;&#x0432;&#x044c;&#x044f;", href: "gesundheitsmanagement.htm"},
                {title: "&#x041d;&#x0430;&#x0443;&#x0447;&#x043d;&#x043e;-&#x0438;&#x0441;&#x0441;&#x043b;&#x0435;&#x0434;&#x043e;&#x0432;&#x0430;&#x0442;&#x0435;&#x043b;&#x044c;&#x0441;&#x043a;&#x0438;&#x0435; &#x043f;&#x0440;&#x043e;&#x0435;&#x043a;&#x0442;&#x044b;", href: "forschung.htm"},
                {title: "&#x0414;&#x0438;&#x0437;&#x0430;&#x0439;&#x043d; &#x0438; &#x0440;&#x0430;&#x0437;&#x0440;&#x0430;&#x0431;&#x043e;&#x0442;&#x043a;&#x0430;", href: "due.htm"},
                {title: "&#x0424;&#x0438;&#x0440;&#x043c;&#x0435;&#x043d;&#x043d;&#x044b;&#x0439; &#x0441;&#x0442;&#x0438;&#x043b;&#x044c;", href: "ci.htm"},
                {title: "&#x041a;&#x0443;&#x043b;&#x044c;&#x0442;&#x0443;&#x0440;&#x0430; &#x0443;&#x043f;&#x0440;&#x0430;&#x0432;&#x043b;&#x0435;&#x043d;&#x0438;&#x044f;", href: "kulturmanagement.htm"},
                {title: "&#x0418;&#x043d;&#x043d;&#x043e;&#x0432;&#x0430;&#x0446;&#x0438;&#x0438;", href: "patente.htm"},
                {title: "&#x0427;&#x0442;&#x043e; &#x043f;&#x0440;&#x043e;&#x0438;&#x0437;&#x0432;&#x043e;&#x0434;&#x0438;&#x0442; &#x043a;&#x043e;&#x043c;&#x043f;&#x0430;&#x043d;&#x0438;&#x044f; M&amp;A", href: "was_macht_mua.htm"},
                {title: "&#x041e;&#x0442;&#x0440;&#x0430;&#x0441;&#x043b;&#x0435;&#x0432;&#x044b;&#x0435; &#x043f;&#x0430;&#x0440;&#x0442;&#x043d;&#x0435;&#x0440;&#x044b;", href: "branchen.htm"},
                {title: "&#x0421;&#x0432;&#x044f;&#x0437;&#x044c;", href: "kommunik.htm"},
                {title: "&#x0412;&#x043d;&#x0435;&#x0448;&#x043d;&#x0438;&#x0435; &#x0441;&#x0441;&#x044b;&#x043b;&#x043a;&#x0438;", href: "links.htm"},
                {title: "e-mail", href: "mailto:info@mattesammann.de"}
            ];
            break;
        default:
            return;
    }
    
    var list = $("<ul class=\"menu\"></ul>");
    
    var clickHandler = function () {
        $(this).removeClass('hover');
        document.location = $(this).children("a").attr("href");
    };
    var mouseOverHandler = function () {
        $(this).addClass('hover');
    };
    var mouseOutHandler = function () {
        $(this).removeClass('hover');
    };
    
    $.each(items, function (index, value) {
        var item = $("<li><a href=\"" + value.href + "\">" + value.title + "</a></li>");
        item.mouseover(mouseOverHandler);
        item.mouseout(mouseOutHandler)
        item.click(clickHandler);
        list.append(item);
    });
    
    container.append(list);
    
    if (lang != "welcome" || (fix === true)) {
        if (testPositionFixed())
            container.css("position", "fixed");
        else {
            var topOffset = container.position().top;
            $(window).scroll(function () {
                container.css("top", getPageYOffset() + topOffset);
            });
        }
    }
}

