/* SF State Template style.js
 * This script will be the default js file to ship with the SF State Template theme.
 */
(function($) {
    Drupal.behaviors.drupaldeveloper = {
        attach: function (context) {

            // Footer position calculation
            if($('#main').length) {
                $(window).on('load resize', function() {
                    /* Get heights of the elements */
                    var headerHeight = $('#header').outerHeight();
                    var footerHeight = $('.footer').outerHeight();
                    var imagebarHeight = $('#imagebar').outerHeight();
                    var mainTopMargin = parseInt($('#main').css('marginTop'));
                    var footerTopMargin = parseInt($('.footer').css('marginTop'));
                    var navHeight = $('#navigation').outerHeight();
                    var sidebarHeight = $('.region-sidebar-second').outerHeight();
                    var mainHeight = $(window).height() - mainTopMargin - headerHeight - imagebarHeight - footerHeight - footerTopMargin;
                    // Find the max of main, nav and sidebar height
                    mainHeight = Math.max(navHeight,sidebarHeight,mainHeight);
                    // Set min height for Main div and content area
                    $('#main').css({"min-height":mainHeight});
                    $('#main section[role="main"]').css({"min-height":mainHeight});
                }).trigger('resize');
            }
            // END Footer position calculation
        }
    }
})(jQuery);