﻿$(document).ready(function () {
    $(".hiddenContent div").hide();
    $('.hiddenContent a, .visibleContent a').click(function () {
        if ($("div", $(this).parent()).is(":visible"))
            $("span", $(this)).html("+");
        else
            $("span", $(this)).html("-");
        slideToggle("div", $(this).parent());
    });

    function slideToggle(el, context) {
        var $el = $(el, context), height = $el.data("originalHeight"), visible = $el.is(":visible");
        var ptop = $el.data("originalPTop"), pbot = $el.data("originalPBot");
        bShow = !visible;

        if (!height || !ptop || !pbot) {
            height = $el.show().height();
            $el.data("originalHeight", height);

            ptop = $el.css("padding-top");
            $el.data("originalPTop", ptop);

            pbot = $el.css("padding-bottom");
            $el.data("originalPBot", pbot);

            if (!visible)
                $el.hide().css({ height: 0 });
        }

        // expand the knowledge (instead of slideDown/Up, use custom animation which applies fix)
        if (bShow) {
            $el.show().animate({ height: height, "padding-top": ptop, "padding-bottom": pbot }, { duration: 250 });
        } else {
            $el.animate({ height: 0, "padding-top": 0, "padding-bottom": 0 }, { duration: 250, complete: function () {
                $el.hide();
            } 
            });
        }
    }
});
