﻿var intLastHeight = 0;
var intMinimumWidth = 0;

function SetDivHeight(blnRepeat) {
    // Get Div heights & widths
    
    var intControlPanelHeight = 0;
    var intHeaderHeight = 0;
    var intContentHeight = 0;
    var intContentWidth = 0;
    var intFooterHeight = 0;
    var intMenuWidth = 0;
    var intMenuHeight = 0;
    var intActualWidth = 0;
    var intPhotoWidth = 0;
    
    if (returnObjById("divControlPanel") != null) {intControlPanelHeight = returnObjById("divControlPanel").offsetHeight;}
    if (returnObjById("divHeader") != null) {intHeaderHeight = returnObjById("divHeader").offsetHeight;}
    if (returnObjById("divContentPane") != null) {intContentHeight = returnObjById("divContentPane").offsetHeight;}
    if (returnObjById("divContentPane") != null) {intContentWidth = returnObjById("divContentPane").offsetWidth ;}
    if (returnObjById("divFooterPane") != null) {intFooterHeight = returnObjById("divFooterPane").offsetHeight;}
    if (returnObjById("divMenu") != null) {intMenuWidth = returnObjById("divMenu").offsetWidth;}
    if (returnObjById("divMenu") != null) {intMenuHeight = returnObjById("divMenu").offsetHeight;}
    if (returnObjById("divPhotoPane") != null) {intPhotoWidth = returnObjById("divPhotoPane").offsetWidth + 200;}
    
    // Check to see if the photos are bigger than the content
    if (returnObjById("divPhotoPane") != null &&
        returnObjById("divPhotoPane").offsetHeight > intContentHeight) {
        intContentHeight = returnObjById("divPhotoPane").offsetHeight;
    }

    // Set Page Height   
    
    var intTotalHeight = 0;
    if (intContentHeight > intMenuHeight) {
        intTotalHeight = intControlPanelHeight + intHeaderHeight + intContentHeight + intFooterHeight ;
    }    
    else {
        intTotalHeight = intControlPanelHeight + intHeaderHeight + intMenuHeight + intFooterHeight ;
    }
    if (intTotalHeight < document.body.clientHeight) {
        intTotalHeight = document.body.clientHeight;
    }
    if (navigator.userAgent.indexOf("Firefox")!=-1) {
        intTotalHeight = window.innerHeight + window.scrollMaxY;
    }
    
    // Get Actual width
        
    intActualWidth = document.body.clientWidth;
    if (intActualWidth < 600){
        intActualWidth = 600;
    }
    
    // Static loop
    if (navigator.userAgent.indexOf("Firefox")!=-1) {
        if (returnObjById("divPageMaster").style.height = intTotalHeight && blnRepeat) {      // Nothing To Do! A repeat call but still the same height.
            setTimeout("SetDivHeight(true)", 10);
            return;
        }
    }
    if (intTotalHeight == intLastHeight && blnRepeat) {      // Nothing To Do! A repeat call but still the same height.
        setTimeout("SetDivHeight(true)", 10);
        return;
    }   
    
    // Set menu axis
    
    intMenuLeft = intActualWidth - intMenuWidth; 

    if (intMenuLeft < intMinimumWidth) {
        intMenuLeft = intMinimumWidth; 
    }
    
    returnObjById("divMenu").style.left = intMenuLeft + "px";
    if (returnObjById("divMenuPic") != null)
        returnObjById("divMenuPic").style.left = (intMenuLeft - 10) + "px";
    
    if (navigator.userAgent.indexOf("Firefox")!=-1) {
        returnObjById("divMenu").style.height = intTotalHeight - (intControlPanelHeight + intHeaderHeight);
    }
    else {
        returnObjById("divMenu").style.height = intTotalHeight - (intControlPanelHeight + intHeaderHeight + intFooterHeight);
    }
    
    // Set background
    
    returnObjById("divPageMaster").style.height = intTotalHeight;
    returnObjById("divPageMaster").style.width = intActualWidth;

    // Set PhotoPane
    
    if (returnObjById("divPhotoPane") != null) {
        if (navigator.userAgent.indexOf("Firefox")!=-1) {
            returnObjById("divPhotoPane").style.height = intTotalHeight - (intControlPanelHeight + intHeaderHeight);
        }
        else {
            returnObjById("divPhotoPane").style.height = intTotalHeight - (intControlPanelHeight + intHeaderHeight + intFooterHeight);
        }  
    }

    // Resize widths
    if (returnObjById("divMenuPic") != null) {
        returnObjById("divMenuPic").style.width = "100px";
    }

    if (returnObjById("divContentPane") != null) {
        
        //
        if ((intActualWidth-intPhotoWidth-intMenuWidth) > (intMinimumWidth-intPhotoWidth))
            returnObjById("divContentPane").style.width = intActualWidth-intPhotoWidth-intMenuWidth;
        else
            returnObjById("divContentPane").style.width = intMinimumWidth-intPhotoWidth;
        
    }
         
    if (returnObjById("divFooterPane") != null) {
        returnObjById("divFooterPane").style.width = intActualWidth - intMenuWidth;
        if (navigator.userAgent.indexOf("Firefox")!=-1) {
            returnObjById("divFooterPane").style.top = (intTotalHeight);
        }
        else {
            returnObjById("divFooterPane").style.top = (intTotalHeight - (intFooterHeight ));
        }  
        
    }

    // End 
            
    intLastHeight = intTotalHeight;
    
    if (blnRepeat) {
        setTimeout("SetDivHeight(true)", 10);
    }

}

function returnObjById( id )
{
    if (document.getElementById) {
        var returnVar = document.getElementById(id);
    }
    else if (document.all) {
        var returnVar = document.all[id];
    }
    else if (document.layers) {
        var returnVar = document.layers[id];
    }
    return returnVar;
}

