﻿//************************************************************************************* 
// File     :   cols.js
// Requires :   prototype.js, mf_domLibrary_0.1.js
// Author   :   Rusty Swayne (rss)
// Origin   :   mindfly.com
// Purpose  :   sets heights of cols to be equal and clears a footer
//*************************************************************************************

var ht_branding     = 157;
var ht_site_info    = 0;
var ht_content_adj  = 0;       
var ht_col_adj      = 0;
var constrain_branding= false; // set to false to ignore widths
var wth_branding	= 960; 
var constrain_content= true; // set to false to ignore widths
var wth_content		= 960; 
/*
var constrain_site_info= false; // set to false to ignore widths
var wth_site_info	= 960; 
*/

// holds the initially displayed height
var min_height      = 0;
var max_col_height  = 0;

var objTimeout = null;

function setupColLayout() {

    // create a list of divs with class col     
    var cols = $$('div.col');
    cols.each( function(col) {
            if(col.offsetHeight > max_col_height)
                max_col_height = col.offsetHeight;
        });
        
}

function setColumnHeights() {
    
    var body = $$('body');
    
    
        // main content div
    var content = $('content');
    
    // create a list of divs with class col     
    var cols = $$('div.col');
            
    
    // determine the dims of the browser
    var winH = getViewportSize()[1];
	var winW = getViewportSize()[0];
	
	// Width adjustments
	if(constrain_branding)
	{
		var branding = $('branding');
		
		if(wth_branding < winW)
		{				
			branding.style.width = wth_branding;
		}
		else { branding.style.width = winW; }
	}
	if(constrain_content)
	{
		if(wth_content < winW)
		{				
			content.style.width = wth_content;
		}
		else { content.style.width = winW; }
	}	
	
	/*
	if(constrain_site_info)
	{
		var site_info = $('site_info');
		if(wth_site_info < winW)
		{				
			site_info.style.width = wth_site_info;
		}
		else { site_info.style.width = winW; }
	}	
	*/
		
	// Height adjustments
   var min_height = winH - (ht_branding + ht_site_info);
   var new_col_height = 0;
   if(max_col_height < min_height) 
   {
   
        new_col_height = min_height;
        
   } else {
    
        new_col_height = max_col_height;
                 
   }      
   
   
   content.style.height = new_col_height + ht_content_adj + 'px'; 
   /*content.setStyle({ 
        height : new_col_height
        });*/
                        
    cols.each( function(col) {
            col.style.height = new_col_height + ht_col_adj + 'px'; 
        });
   
        clearTimeout(objTimeout);
        objTimeout = null;
              
}




addLoadEvent(setupColLayout);
addLoadEvent(setColumnHeights);
addOnresizeEvent(setColumnHeights);
//window.setInterval('setColumnHeights()', 50);



