﻿/// <reference path="jquery-1.4.2.min.js" />
/// <reference path="TriFinance.StartUp.js" />

function CreateElement(tagName, className, itemContent, parentItemToAppendTo) {
    var createdElement = $j("<" + tagName + " />");
    createdElement.addClass(className);

    if (itemContent)
        createdElement.append(itemContent);

    if (parentItemToAppendTo)
        parentItemToAppendTo.append(createdElement);

    return createdElement;
}

/* FAQ Sliding */
$j(document).ready(function () {
    $j(".question").click(function () {
        var category = $j(this).parents(".FAQCategory");

        //if all Answers are expanded [AB]
        if ($j(".hideAll", category).css("display") == "block") {
            var answer = $j(this).next();

            answer.slideToggle(200);
            answer.toggleClass("answerInvisible");
            answer.toggleClass("answerVisible");
            $j(this).toggleClass("arrowsToBottom");
            $j(this).toggleClass("arrowsToTop");


            if ($j(".answerVisible", category).size() == 0) {
                $j(".hideAll").css("display", "none");
                $j(".showAll").css("display", "block");
            }
        }

        else {
            var activeAnswer = $j(".answerVisible", category);
            var answer = $j(this).next();

            answer.slideToggle(200);
            answer.toggleClass("answerInvisible");
            answer.toggleClass("answerVisible");
            $j(this).toggleClass("arrowsToBottom");
            $j(this).toggleClass("arrowsToTop");


            activeAnswer.not(answer).slideToggle(200);
            activeAnswer.not(answer).toggleClass("answerVisible");
            activeAnswer.not(answer).toggleClass("answerInvisible");

        }
    });

    /* Show all FAQs for a category */
    $j(".showAll").click(function () {
        var answers = $j(".answerInvisible", $j(this).parent(".category").next(".FAQList"));
        var questions = $j(".arrowsToBottom", $j(this).parent(".category").next(".FAQList"));

        answers.slideToggle(200);
        answers.removeClass("answerInvisible").addClass("answerVisible");

        $j(this).css("display", "none");
        $j(this).next(".hideAll").css("display", "block");

        questions.removeClass("arrowsToBottom").addClass("arrowsToTop");
    });

    $j(".hideAll").click(function () {
        var answers = $j(".answerVisible", $j(this).parent(".category").next(".FAQList"));
        var questions = $j(".arrowsToTop", $j(this).parent(".category").next(".FAQList"));

        answers.slideToggle(200);
        answers.removeClass("answerVisible").addClass("answerInvisible");

        $j(this).css("display", "none");
        $j(this).prev(".showAll").css("display", "");

        questions.removeClass("arrowsToTop").addClass("arrowsToBottom");
    });


    /* Handle Heights in Lists */
    var itemsLeft = $j('.LeftItem');

    itemsLeft.each(function () {
        var item = $j(this);
        if (item.next('.RightItem').height() > item.height()) {
            item.height(item.next('.RightItem').height());
        }
        else if (item.height() > item.next('.RightItem').height()) {
            item.next('.RightItem').height(item.height());
        };
    });

    /* Handle Content-Height */
    var content = $j(".Content");
    var hoehe = content.height();
    if (hoehe < 600) {
        content.height(hoehe + 150);
    };

    /* Handle Footer Width */
    var TestContainer = $j("#WidthTest");
    var StaticTextContainer = $j(".FooterStaticText");
    var TextContainer = $j(".FooterText");
    var ItemsContainer = $j(".FooterItems");
    var MaxWidth = $j("#ContentCarrier").width();

    TestContainer.html(TextContainer.html());

    if (TestContainer.width() > MaxWidth) {

        TestContainer.html(StaticTextContainer.html());
        StaticTextContainer.width(TestContainer.width());

        TextContainer.width(MaxWidth);
        var ItemsContainerWidth = MaxWidth - StaticTextContainer.width();
        ItemsContainer.width(ItemsContainerWidth);



        var FooterContainer = $j(".FooterContainer", ItemsContainer);
        var width = 0;
        FooterContainer.each(function () {
            var current = $j(this);
            width += current.width();
            if (!current.hasClass("FirstContainer")) {
                width += 40;
            };
        });
        if (width > ItemsContainerWidth) {
            ItemsContainer.append("<div id='FooterFirstRow'></div>").append("<div class='Clearer' style='height: 10px;'></div>").append("<div id='FooterSecondRow'></div>");
            var widthFooter = 0;
            var firstRow = $j("#FooterFirstRow");
            var secondRow = $j("#FooterSecondRow");
            //            FooterContainer.each(function () {
            //                var current = $j(this);
            //                widthFooter += current.width();
            //                if (widthFooter < ItemsContainerWidth) {
            //                    firstRow = firstRow.append(current);
            //                }
            //                else {
            //                    secondRow = secondRow.append(current);
            //                }
            //            });
            var count = 0;
            while (count < FooterContainer.size()) {
                var current = $j(FooterContainer[count]);
                widthFooter = widthFooter + current.width();
                if (!current.hasClass("FirstContainer")) {
                    widthFooter += 40;
                }
                if (widthFooter < ItemsContainerWidth) {
                    firstRow = firstRow.append(current);
                }
                else {
                    secondRow = secondRow.append(current);
                }
                count++;
            }
            secondRow.children().first(".FooterContainer").addClass("FirstContainer").css("margin-left", "0px");
            $j(".FooterItems").html(ItemsContainer.html());
        }
        else {
            $j(".FooterItems").width(ItemsContainerWidth);
        }

    }
    else {

        TextContainer.width(TestContainer.width());
    }




});

/* Bubble Navigation */

function showBubble(key, sender) {
    alert($j(sender).position().left);
    $j("#" + key).css("display", "block").css("left", $j(sender).position().left);
}

function hideBubble(key) {
    $j("#" + key).css("display", "none");
}


$j(document).ready(function () {
    $j("#firstStep").click(function () {
        $j("#secondStep").css("visibility", "visible");
        $j("#thirdStep").css("visibility", "visible");
    });

    /* change image bottom */
//    var bubbleMenus = $j(".BubbleMenu");
//    bubbleMenus.each(function () {
//        var currentBubble = $j(this);
//        if ($j(".MenuLink", currentBubble).size() < 3)) {
//            $j(".Bottom", currentBubble).css("background-image", "url('/Images/Menus/Level_2/bottom_black.png');");
//        }
//    });
});

/* SubNavigation */

//[FK] menu functions
function openBubble(obj) {
    $j(obj).children("div.BubbleMenu").css("display", "block").css("left", "-" + $j(obj).children("div.BubbleMenu").width()/4 + "px");
    if ($j(obj).children("div.BubbleMenu").children(".MenuLink").size() < 2) {
        $j(obj).children("div.BubbleMenu").children(".Bottom").css("background-image", "url('/Images/Menus/Level_2/bottom_black.png')");
    }
}

function closeBubble(obj) {
    $j(obj).children("div.BubbleMenu").css("display", "none");
}

function subMenu(obj) {
    $j(obj).children(".BubbleSubMenu").css("display", "block");
    if ($j(obj).children("div.BubbleSubMenu").children(".SubWrap").children(".SubMenuLink").size() < 2) {
        $j(obj).children("div.BubbleSubMenu").children(".SubBottom").css("background-image", "url('/Images/Menus/Level_3/submenu_bottom_black.png')");
    }
}
function closeSub(obj) {
    $j(obj).children(".BubbleSubMenu").css("display", "none");
}

function closeMenu(obj) {
    $j(obj).css("display", "none");
}

function keepOpen() {

}


$j(document).ready(function () {
    var subWraps = $j(".SubWrap");
    subWraps.each(function () {
        var current = $j(this);
        if (!current.children(".SubMenuLink").size() > 0) {
            current.parent(".BubbleSubMenu").parent().removeClass("HasSubMenu");
            current.parent(".BubbleSubMenu").remove();
        }
    });

});




