﻿$(window).load(function () {
    var exactheight = 500;

    var LeftSchool = $('div.LeftSchool').not('.noFixedHeight');
    var LeftSchoolHeight = LeftSchool.height();

    var LeftDistrict1 = $('div.LeftDistrict1').not('.noFixedHeight');
    var LeftDistrict1Height = LeftDistrict1.height();

    var LeftDistrict2 = $('div.LeftDistrict2').not('.noFixedHeight');
    var LeftDistrict2Height = LeftDistrict2.height();

    var Middle3Column = $('div.Middle3Column').not('.noFixedHeight');
    var Middle3ColumnHeight = Middle3Column.height();

    var Right3Column = $('div.Right3Column').not('.noFixedHeight');
    var Right3ColumnHeight = Right3Column.height();

    var Right2Column = $('div.Right2Column').not('.noFixedHeight');
    var Right2ColumnHeight = Right2Column.height();

    if (LeftSchoolHeight > 0) {
        if (Right2ColumnHeight > 0) {
            if (Right2ColumnHeight > LeftSchoolHeight && Right2ColumnHeight > exactheight) {
                LeftSchool.height(Right2ColumnHeight);
                Right2Column.height(Right2ColumnHeight + 9);
            }
            else if (Right2ColumnHeight < LeftSchoolHeight && LeftSchoolHeight > exactheight) {
                LeftSchool.height(LeftSchoolHeight);
                Right2Column.height(LeftSchoolHeight + 9);
            }
            else {
                LeftSchool.height(exactheight);
                Right2Column.height(exactheight + 9);
            }

        }
        else {
            if (LeftSchoolHeight > Middle3ColumnHeight && LeftSchoolHeight > Right3ColumnHeight && LeftSchoolHeight > exactheight) {
                LeftSchool.height(LeftSchoolHeight);
                Middle3Column.height(LeftSchoolHeight + 9);
                Right3Column.height(LeftSchoolHeight + 11);
            }
            else if (Middle3ColumnHeight > LeftSchoolHeight && Middle3ColumnHeight > Right3ColumnHeight && Middle3ColumnHeight > exactheight) {
                LeftSchool.height(Middle3ColumnHeight);
                Middle3Column.height(Middle3ColumnHeight + 9);
                Right3Column.height(Middle3ColumnHeight + 11);
            }
            else if (Right3ColumnHeight > LeftSchoolHeight && Right3ColumnHeight > Middle3ColumnHeight && Right3ColumnHeight > exactheight) {
                LeftSchool.height(Right3ColumnHeight);
                Middle3Column.height(Right3ColumnHeight + 9);
                Right3Column.height(Right3ColumnHeight + 11);
            }
            else {
                LeftSchool.height(exactheight);
                Middle3Column.height(exactheight + 9);
                Right3Column.height(exactheight + 11);
            }
        }

    }
    else {
        var FullLeftDistrictHeight = LeftDistrict1Height + LeftDistrict2Height;

        if (Right2ColumnHeight > 0) {
            if (Right2ColumnHeight > FullLeftDistrictHeight && Right2ColumnHeight > exactheight) {
                var leftheightleftover = Right2ColumnHeight - FullLeftDistrictHeight;
                LeftDistrict2.height(leftheightleftover + LeftDistrict2Height);
                Right2Column.height(Right2ColumnHeight + 65);
            }
            else if (Right2ColumnHeight < FullLeftDistrictHeight && FullLeftDistrictHeight > exactheight) {
                Right2Column.height(FullLeftDistrictHeight + 65);
            }
            else {
                var leftheightleftover = exactheight - FullLeftDistrictHeight;
                LeftDistrict2.height(LeftDistrict2Height + leftheightleftover);
                Right2Column.height(exactheight + 65);
            }

        }
        else {
            if (FullLeftDistrictHeight > Middle3ColumnHeight && FullLeftDistrictHeight > Right3ColumnHeight && FullLeftDistrictHeight > exactheight) {
                Middle3Column.height(FullLeftDistrictHeight + 65);
                Right3Column.height(FullLeftDistrictHeight + 65);
            }
            else if (Middle3ColumnHeight > FullLeftDistrictHeight && Middle3ColumnHeight > Right3ColumnHeight && Middle3ColumnHeight > exactheight) {
                var leftheightleftover = Middle3ColumnHeight - FullLeftDistrictHeight
                LeftDistrict2.height(LeftDistrict2Height + leftheightleftover);
                Right3Column.height(Middle3ColumnHeight + 65);
                Middle3Column.height(Middle3ColumnHeight + 65);
            }
            else if (Right3ColumnHeight > FullLeftDistrictHeight && Right3ColumnHeight > Middle3ColumnHeight && Right3ColumnHeight > exactheight) {
                var leftheightleftover = Right3ColumnHeight - FullLeftDistrictHeight
                LeftDistrict2.height(LeftDistrict2Height + leftheightleftover);
                Middle3Column.height(Right3ColumnHeight + 65);
                Right3Column.height(Right3ColumnHeight + 65);
            }
            else {
                var leftheightleftover = exactheight - FullLeftDistrictHeight
                LeftDistrict2.height(LeftDistrict2Height + leftheightleftover);
                Middle3Column.height(exactheight + 65);
                Right3Column.height(exactheight + 65);
            }
        }


    }

});
