﻿function SetButton() {
    var zindex = 0;
    $("#pnlSubNavigation ul li").not('#pnlSubNavigation ul ul li').each(function () {
        $(this).css("margin-bottom", parseInt($(this).css("margin-bottom").replace("px", "")) + 10 * zindex);
        $(this).css("margin-top", -10 * zindex);
        $(this).css("z-index", zindex++);
    });

    $('#pnlSubNavigation ul li').each(function () {
        var subZindex = 0;
        $('ul li', this).each(function () {
            $(this).css("margin-bottom", parseInt($(this).css("margin-bottom").replace("px", "")) + 10 * subZindex);
            $(this).css("margin-top", -10 * subZindex);
            $(this).css("z-index", subZindex++);
        });
    });
}

$(function () {
    ShowEditButtons();
    InitEditor();
});

function ShowEditButtons() {
    $(".pnlModuleWrapper.UserIsLoggedIn").hover(
    function () {
        $(this).children(".pEditHeader").css("display", "block");
    }, function () {
        $(this).children(".pEditHeader").css("display", "none");
    });
}

// show delete Comment Button on hover 
$(function () {
    $(".pnlComments.UserIsLoggedIn").hover(
    function () {
        $(".pCommentDate a.lnkDelete").css("visibility", "visible");
    },
    function () {
        $(".pCommentDate a.lnkDelete").css("visibility", "hidden");
    });
});

function InitEditor() {

    $(".lnkShowEditor").each(function () {
        var a = $(this);
        a.click(function () {
            $(this).tooltip().hide();
            $.ajax({
                url: $(this).attr("href"),
                success: function (data) {
                    a.parent().parent("div").html(data);
                    $('.pEditHeaderActiveEditor a').each(function () {
                        $(this).tooltip();
                    });

                    // prevent editor from getting BgColor through hover
                    $(".pnlEditEditor.UserIsLoggedIn").parent().hover(
                    function () {
                        $(this).css("background-color", "transparent");
                    });
                }
            });
            return false;
        });
    });
}

$(function () {
    $('.pnlMainNavigation ul li:not(".first"):last-child').addClass('last');
    $('.pnlSubNavigation ul li:not(".first"):last-child').addClass('last');
    $('.pnlSubNavigation ul ul li:not(".first"):last-child').addClass('last');
});

// Paging for Comments
$(function () {
    $("ul.paging").quickPager({ pagerLocation: "both" });
});

// Content should have at least same height as Subnavi + Teasers 
$(function () {
    var subNavHeight = $("#pnlSubNavigation").height();
    var subNavTop = parseInt($("#pnlSubNavigation").css("top"), 10);
    var minContentHeight = subNavHeight + subNavTop;
    if (minContentHeight > 0) {
        $(".pnlContent").css("min-height", minContentHeight);
    } else {
        $(".pnlContent").css("min-height", "20px");
    }
});


// Moduldesign --> set background-color & border-color
$(function () {

    // set NL input background-color
    $('.pnlNewsletterInputBackgroundColor .txtFullWidth, .pnlNewsletterInputBackgroundColor select').css({ "background": "0", "background-color": $(".pnlNewsletterWrapper").attr("data-input-background-color") });
    // set NL input border
    $('.pnlNewsletterInputBorderColor .txtFullWidth, .pnlNewsletterInputBackgroundColor select').css({ "border": "1px solid " + $(".pnlNewsletterWrapper").attr("data-input-border-color") });

    // set Comments input background-color
    $('.pnlCommentsInputBackgroundColor .txtFullWidth, .pnlCommentsInputBackgroundColor .txtMultiline').css({ "background": "0", "background-color": $(".pnlCommentPostsForm").attr("data-input-background-color") });
    // set Comments input border
    $('.pnlCommentsInputBorderColor .txtFullWidth, .pnlCommentsInputBorderColor .txtMultiline').css({ "border": "1px solid " + $(".pnlCommentPostsForm").attr("data-input-border-color") });

    // set Guestbook input background-color
    $('.pnlGuestbookInputBackgroundColor .txtFullWidth, .pnlGuestbookInputBackgroundColor .txtMultiline').css({ "background": "0", "background-color": $(".pnlGuestbooksForm").attr("data-input-background-color") });
    // set Guestbook input border
    $('.pnlGuestbookInputBorderColor .txtFullWidth, .pnlGuestbookInputBorderColor .txtMultiline').css({ "border": "1px solid " + $(".pnlGuestbooksForm").attr("data-input-border-color") });

    // set SimpleForm input background-color
    $('.pnlSimpleFormInputBackgroundColor .txtFullWidth, .pnlSimpleFormInputBackgroundColor .txtMultiline').css({ "background": "0", "background-color": $(".pnlSimpleForm").attr("data-input-background-color") });
    // set SimpleForm input border
    $('.pnlSimpleFormInputBorderColor .txtFullWidth, .pnlSimpleFormInputBorderColor .txtMultiline').css({ "border": "1px solid " + $(".pnlSimpleForm").attr("data-input-border-color") });
});

// AWC Fore/Background switch
$(function () {

    // add classes to awc --> depends on z-index
    $(".pnlAnyWhereContentModule, .pnlFlexSlideGallery, .pnlFlexAudioModule").each(function () {
        var awcModule = $(this);
        //alert(awcModule.css("z-index"));
        if (awcModule.css("z-index") > 0) {
            awcModule.addClass("flexInForeground");
        } else {
            awcModule.addClass("flexInBackground");
        }
    });

    // Show Flexies Button if design-awc is on THIS page
    if ($(".flexInBackground").length) {
        $("#lnkSwitchFlexLayer").css("visibility", "visible");
    }

    // Flexies Button click event to manipulate awc with class (flexInBackground)
    $("#lnkSwitchFlexLayer").click(function () {
        var item = $(this).find(".aFirst");
        if (item.hasClass("flexiesInBackground")) {
            item.removeClass("flexiesInBackground").addClass("flexiesInForeground").text("Flex in den Hintergrund");
            $(".flexInBackground").css("z-index", 111);
        } else {
            item.removeClass("flexiesInForeground").addClass("flexiesInBackground").text("Flex in den Vordergrund");
            $(".flexInBackground").css("z-index", -1);
        }
    });
});

// popup für videos
// breite wird im link als attribut gesetzt (data-width), höhe ebenso (data-height)
$(function () {
    $(".lnkPlayVideo").click(function () {

        var popupLink = $(this),
            width = popupLink.attr("data-width"),
            height = popupLink.attr("data-height");

        // setzte defaults wenn attribut nicht vorhanden
        if (typeof width == "undefined") width = 858;
        if (typeof height == "undefined") height = 512;

        popupLink.colorbox({
            iframe: true,
            innerWidth: width,
            innerHeight: height
        });
    });
});



