﻿
$(document).ready(function() {
    /*
    * Custom layout-related fixes
    */
    var shadowHeight = $("#content-area").height() + 70;
    $("#left-shadow").css("height", shadowHeight);
    $("#right-shadow").css("height", shadowHeight);
    
    /* Main navigation vertical align */
    $("#main-navi .menu-item-text").equalHeights({ notBlock: true });
    
    /* Search results active tab dom-tree fix */
    if ($("#scopeTabs").length > 0) {
        $("#scopeTabs .ms-sctabcn").wrapInner(function () {
            return '<span></span>';
        });
    }
});

(function ($) {
    $.fn.equalHeights = function (customSettings) {
        var config = { 'notBlock': 'false' }
        if (customSettings) $.extend(config, customSettings);

        var maxHeight = 0;
        this.each(function () {
            if (this.offsetHeight > maxHeight) { maxHeight = this.offsetHeight; }
        });

        this.each(function () {
            if (customSettings) {
                if (this.offsetHeight < maxHeight) {
                    var padding = maxHeight - this.offsetHeight;
                    $(this).css("padding-top", padding/2);
                }
            } else {
                if (this.offsetHeight > maxHeight) { maxHeight = this.offsetHeight; }
                $(this).height(maxHeight + "px");
                if (this.offsetHeight > maxHeight) {
                    $(this).height((maxHeight - (this.offsetHeight - maxHeight)) + "px");
                }
            }
        });

        return this;
    };

})(jQuery);
