/******************************************************************************
* cmJQuery.js
******************************************************************************/

function equalHeight(group) {
    var tallest = 0;
    group.each(function () {
        var thisHeight = $(this).height();
        if (thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}

$(window).load(function () {
    equalHeight($("#cmPaneCenterPadding div.insInset div.cmInset-summary .insContent"));
    equalHeight($("#cmPaneCenterPadding div.insInset div.cmInset-summary h3.insTitle-bg-img span"));

    $('.cmContentZoneTopHome .cmInset-plain .bsImage').appendTo($('.cmContentZoneTopHome .cmInset-plain .insFullcontent'));
    $('.cmContentZoneTopHome .cmInset-plain-grey .bsImage').appendTo($('.cmContentZoneTopHome .cmInset-plain-grey .insFullcontent'));

    equalHeight($(".cmContentBlock.cmHome .cmInset-color .insContent"));
    equalHeight($(".cmContentBlock.cmHome .cmInset-color h3.insTitle-bg-img span"));

    $('.cmContentBlock.cmHome .cmInset-color').each(function () {
        var $this = $(this);
        $('.bsImage:last', $this).appendTo($('.insFullcontent', $this));
    });

    $('#cmPaneCenterPadding > div.insInset > div.cmInset-summary').each(function () {
        var $this = $(this);
        $('.tocToc', $this).appendTo($('.insFullcontent', $this)).show();
        $('.bsDiscList', $this).before('<div class="bsDiscListOuter"></div>').appendTo($(".bsDiscListOuter", $this).css('min-height', $this.parent().height()));
    });

    $(".tocToc h3").bind({
        click: function () {
            $('.bsDiscListOuter').fadeOut('slow');
            $('.bsDiscListOuter', $(this).parent()).fadeIn('slow');
        },
        clickoutside: function () {
            $('.bsDiscListOuter', $(this).parent()).fadeOut('slow');
        }
    });
});
