﻿//Sizes the main content div when browser windows changes/loads
function DisplayContentDiv() {    
    var MIN_CONTENT_HEIGHT = 150;
    //get elements
    var fullScreenDiv = $('divMainContentFullScreen');
    var dynamicChild = $('divMainContentDynamicChild');
    var fullScreenChild = $('divMainContentFullScreenChild');
    var dynamicDiv = $('divMainContentDynamic');
    var header = $('header').getHeight();
    var footer = $('footer').getHeight();
    //get height of window
    var height = document.viewport.getHeight();
    height = height - header - footer;
    if (fullScreenChild.childElements().length > 0) //MainContentFullScreen not empty
    {
        if (dynamicChild.childElements().length > 1) {
            throw 'WARNING: YOU ARE USING BOTH THE FULLSCREEN AND DYNAMIC PLACEHOLDERS!!!!';
        }
        //set div height
        if (height < MIN_CONTENT_HEIGHT) {
            height = MIN_CONTENT_HEIGHT;
        }
        fullScreenDiv.style.height = height + 'px';
        //hide dynamic div
        dynamicDiv.style.display = "none";

        fullScreenChild.childElements().each(function(e) { if (e.onresize) e.onresize(); });
    }
    else //MainContentDynamic
    {
        //hide full screen div
        fullScreenDiv.style.display = 'none';
        //set div min-height
        if (height < MIN_CONTENT_HEIGHT) {
            height = MIN_CONTENT_HEIGHT;
        }
        if (usingIE6) {
            dynamicDiv.style.height = height + 'px';
        }
        else {
            dynamicDiv.style.minHeight = height + 'px';
        } 
    }
}

Event.observe(window, 'load', DisplayContentDiv);
Event.observe(window, 'resize', DisplayContentDiv);
