/* This script calculates heights of zones in col 2 and 3 of the home page and add fillers */
// Add the fillers here
fillers = new Array('f_colts', 'f_welfare');

/* Calculate heights */
function runFormat() {
	var filler = new Array();
	var format = new Array();
	var format_col1 = document.getElementById('format_col1').offsetHeight;
	var format_col2 = document.getElementById('format_col2').offsetHeight;
	
	for(i=0; i<fillers.length; i++) {
		filler[i] = document.getElementById(fillers[i]);
		filler[i].style.display='block';
		format[i] = filler[i].offsetHeight;
		filler[i].style.display='none';
	}
	
	if(format_col1 < format_col2) {
		document.getElementById('format_col1').style.borderBottomStyle = 'solid';
		document.getElementById('format_col1').style.borderBottomColor = '#ccc';
		document.getElementById('format_col1').style.borderBottomWidth = (format_col2 - format_col1) + 'px';
	}
	else {
		diff = format_col1 - format_col2;
		selection = 0;
		// Find the smallest difference between each filler and the gap to fill
		for(i=0;i<format.length; i++) {
			if(Math.abs(diff - format[i]) < Math.abs(diff - format[selection])) selection = i;
		}
		// Only include the filler if it its height is less than twice the gap
		if(filler[selection].offsetHeight < diff * 2) {
			// Display the filler
			filler[selection].style.left='auto';
			filler[selection].style.display='block';
		}
		// Now calculate the gap left
	gap = filler[selection].offsetHeight - Math.abs(format_col1 - format_col2);
	
	// Now add solid fill
	colToFill = gap > 0 ? 1 : 2;
	document.getElementById('format_col' + colToFill).style.borderBottomStyle = 'solid';
	document.getElementById('format_col' + colToFill).style.borderBottomColor = '#ccc';
	document.getElementById('format_col' + colToFill).style.borderBottomWidth = Math.abs(gap) + 'px';		
	}
}

