/**
 * McKinley Footer Init Script
 * init loader
 */

// IE DEBUG HACK

if (typeof console == "undefined") {
    var console = {
        log : function () {
            return false;
        },
        dir : function () {
            return false;
        }
    }
}

var menucheck = false;

function onDocumentLoad() {

    var e;
    /**
     * Main Menu
     */
    try {
        if ($('menu') != null) {
            new eu.mckinley.slider.dropdown([ $$('#menu ul li'),  $$('#menu ul li ul'), $$('#menu ul li ul li') ]);
        }
    }
    catch (e) {
        // throw e;
    }
    /**
     * Produktmanagement (Menu)
     */
    try {
        productSelection = new eu.mckinley.products.selection($$('#menuproductselection div.section'));
    }
    catch (e) {
        // throw e;
    }
    /**
     * CampaignPopup
     */
    try {
        if ($('campaign')) {
            try {
                $('portalteaser').hide();
            }
            catch (e) {
            }
            campaignPopup = new eu.mckinley.popup.campaign($('campaign'));
        }
    }
    catch (e) {
        // throw e;
    }
    /**
     * CampaignSlider
     */
    try {
        if ($('campaignslider')) {
            campaignSlider = new eu.mckinley.slider.campaign($('campaignslider'));
        }
    }
    catch (e) {
        //throw e;
    }
    /**
     * Produktuebersicht
     */
    try {
        if ($('resultslider')) {
            searchSlider = new eu.mckinley.slider.search($('resultslider'));
        }
    }
    catch (e) {
        //throw e;
    }
    /**
     * Product Tabs
     */
    try {
        productTab = new eu.mckinley.products.tab($$('#tabbox li'));
    }
    catch (e) {
        throw e;
    }

    /**
     * ProductColorswitch
     */

    try {
        if ($('productcolors') && (websiteconfig["product"] > 0 )) {
            new eu.mckinley.products.colors($('productcolors'));
        }
    }
    catch (e) {
        throw e;
    }

    /**
     * Product Flash
     */
    try {
        if ($('productzoom')) {
            var playerVersion = swfobject.getFlashPlayerVersion();
            if (playerVersion.major >= 9) {
                swfobject.embedSWF("/static/swf/zoomer.swf", "productzoom", "380", "390", "8.0.0", "/static/swf/expressInstall.swf", productflashvars, params);
            }
        }
    }
    catch (e) {
        //throw e;
    }
    /**
     * Product Slider
     */
    try {
        if ($('productslider_prev')) {
            productSlider = new eu.mckinley.slider.product($('slider'));
        }
    }
    catch (e) {
        //throw e;
    }

    /**
     * Cookie Handling
     */
    try {
        mckinleycookie = new CookieJar();
    }
    catch (e) {
    }
    /**
     * Teambox and all stuff arround it
     */
    try {
        if ($('teambox')) {
            myteambox = new eu.mckinley.products.teambox($('teambox'));
            /**
             * Teambox Slider
             */
            try {
                if ($('products')) {
                    teamboxSlider = new eu.mckinley.slider.teambox($$('#products div.product'));
                }
            }
            catch (e) {
                //throw e;
            }

        }

    }
    catch (e) {
        throw e;
    }


    /**
     * Google Maps
     */
    try {
        if ($('googlemap') && typeof initializeMap == "function") {
            initializeMap();
        }
    }
    catch (e) {
        throw e;
    }

    /**
     * Image Replacement (for Mac)
     */
    if (websiteconfig.imagereplace) {
        try {
            var imageReplacer = new at.elements.textreplace.image("/cache/headlines/", {
                appendFilename: true
            });
            imageReplacer.add({
                elements: $$('#menu span.img'),
                options: {
                    font: 'ChaparralPro-Regular.ttf',
                    width: '',
                    height: '12',
                    color: '010101',
                    size: '10',
                    positionx: 0,
                    positiony: 12,
                    adjust: 100,
                    replaceElement: {
                        tagName: "span",
                        className: "imgdone"
                    },
                    modifyValue : function (vari) {
                        return vari.toUpperCase();
                    }
                }
            });
            imageReplacer.add({
                elements: $$('#campaign .headline h1'),
                options: {
                    font: 'ChaparralPro-Regular.ttf',
                    width: '160',
                    height: '32',
                    color: 'e60000',
                    size: '24',
                    positionx: 0,
                    positiony: 24,
                    adjust: 100,
                    replaceElement: {
                        tagName: "h1",
                        className: "imgdone"

                    }
                }
            });
            imageReplacer.add({
                elements: $$('#campaign .headline span'),
                options: {
                    font: 'ChaparralPro-Regular.ttf',
                    width: (websiteconfig.campaign - 180),
                    height: '32',
                    color: '000000',
                    size: '24',
                    positionx: 0,
                    positiony: 24,
                    adjust: 120,
                    replaceElement: {
                        tagName: "span",
                        className: "imgdone"
                    }
                }
            });
            imageReplacer.add({
                elements: $$('#content .headline h1'),
                options: {
                    font: 'ChaparralPro-Regular.ttf',
                    width: '580',
                    height: '32',
                    color: 'e60000',
                    size: '24',
                    positionx: 0,
                    positiony: 24,
                    adjust: 100,
                    replaceElement: {
                        tagName: "h1",
                        className: "imgdone"
                    }
                }
            });
            imageReplacer.start();
        }
        catch (e) {
            throw e;
        }
    }


    if ($$(".filetree")) {
        var containers = $$(".filetree ul li");
        var subcontainers = $$(".filetree ul li ul");
        for (var i = 0; i < containers.length; i++) {
            containers[i].getElementsBySelector("span")[0].observe("click", function () {
                this.getElementsBySelector("ul")[0].toggle();
            }.bind(containers[i]));

        }
        for (var i = 0; i < subcontainers.length; i++) {
            subcontainers[i].hide();
        }
    }

}

function DocumentUnLoad() {
    try {
        if ($('storeMap') != null) {
            GUnload();
        }
    }
    catch (e) {
    }
}

function gotoLink(htmlElement) {
    if (htmlElement.href) {
        location.href = htmlElement.href;
    }
    else {
        if (htmlElement.childNodes) {
            if (htmlElement.getElementsByTagName("a")) {
                location.href = htmlElement.getElementsByTagName("a")[0].href;
            }
        }
    }
}
function gotoUrl(url) {
    if (!menucheck) {
        menucheck = true;
        location.href = url;
    }
}

function popupopen(url) {
    mypopup = window.open(url, "popup", "width=570,height=600,left=100,top=200,scrollbars=yes,status=no,toolbar=no,menubar=no,resizeable=no");
    mypopup.focus();
}

function popupclose() {
    window.close();
}

try {
    window.onunload = DocumentUnLoad;
}
catch (e) {
}

