/*
	YUI grids columnfix
	written by Christian Heilmann (http://wait-till-i.com)
	either just include or call with YAHOO.util.grids.columnfix.fix(gridgroup);
*/
YAHOO.namespace('util.grids');
YAHOO.util.grids.columnfix = function(){
	function fixcolumns(){
		var tofix = YAHOO.util.Dom.getElementsByClassName('columnfix','div',this);
		var divs = tofix.length > 0 ? tofix : this.getElementsByTagName('div');
		for(var i=0;divs[i];i++){
			if(divs[i].className.indexOf('yui-g') !== -1){
				fix(divs[i]);
			};
		};
	};
	function fix(grid){
		if(YAHOO.util.Dom.inDocument(grid)){
			var region = YAHOO.util.Dom.getRegion(grid);
			var region_height = region.bottom - region.top;
			//alert(region.bottom+' '+region.top);
			var height=0;
			var con_height=document.getElementById('loaded_page').offsetHeight;
			//var con_height=document.getElementById('content').offsetHeight;
    		var nav_height=document.getElementById('navigation').offsetHeight-1;
    		var ads_height=document.getElementById('ads').offsetHeight-2;
			var sep_height=0;
			if(document.getElementById('coach_tab')){
			con_height=document.getElementById('coach_tab').offsetHeight+2;
			document.getElementById('coach_pics').style.height=document.getElementById('coach_tab').offsetHeight-3;
			}
			if(document.getElementById('schedule2')){
			sep_height=document.getElementById('schedule2').offsetHeight+document.getElementById('roster_table').offsetHeight;
			document.getElementById('schedule_back').style.height=document.getElementById('schedule2').offsetHeight;
			//alert("the height of the table is "+sep_height);
			}
			//alert(region_height+' '+con_height+' '+nav_height+' '+ads_height);
			/*if(region_height> con_height && region_height>nav_height && region_height>ads_height && region_height>600){
				height=region_height;
			}
			else*/
			 if(con_height>1000 && con_height>nav_height && con_height>ads_height){
				height=con_height;
			}
			else if(nav_height>1000 && nav_height>ads_height){
				height=nav_height;
			}
			else if(ads_height>1000){
				height=ads_height;
			}
			else {
				height=1000;
			}
			if(height<(sep_height+352)){
				height=(sep_height+352);
			}
			//height=height-2;		
			var columns = YAHOO.util.Dom.getElementsByClassName('yui-u','div',grid);
			for(var i=0;columns[i];i++){
			//	alert(columns[i].id+' '+height);
				YAHOO.util.Dom.setStyle(columns[i],'height',height+'px');
			};
		}
		YAHOO.util.Dom.setStyle('content_main','height',height+'px');
		YAHOO.util.Dom.setStyle('loaded_page','height',height+'px');
		YAHOO.util.Dom.setStyle('ads','height',height+'px');
		YAHOO.util.Dom.setStyle('nav_bottom','height',height-304+'px');
	};
	YAHOO.util.Event.onContentReady('bd',fixcolumns);
	return{fix:fix};
}();
