/*
 *	syncBottoms.js
 *	This subroutine will sync the bottoms of blocks which are out of sync (at runtime).
 *
 *	Version: 1 
 *	   Date: 2008-08-04
 *	 Author: Monty Dickerson <monty@infinityprosports.com>
 *	
 *	Dependencies:
 *	1. Requires the jQuery ajax library: http://jquery.com/
 *		e.g. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
 *	2. For debug code to not break non-FF browsers load the stub firebugx: http://getfirebug.com/lite.html
 *		e.g. <script type="text/javascript" src="/path/to/firebug/firebugx.js"></script>
 *	
 *	Prerequisites:
 *	1. Before calling, wait until loading the DOM and any images which could affect vertical position of blocks on the page;
 *	2. Assign the className (e.g. 'sync-bottom') to the (2 or more) elements you want to sync;
 *	3. Define the class (e.g. 'sync-bottom') in your stylesheet.css and give it any position property besides the default (static), e.g. position:relative;
 *	4. Example invocation: syncBottoms('.sync-bottom');
 *	
 *	Features: 
 *	1. Adjusts block heights to make the blocks' bottoms level;
 *	2. Blocks can have (the same or) different offsetTop;
 *	
 *	Limitations:
 *	1. Blocks can not be vertically stacked (i.e. in the same column) such that changing the height of one would affect another's offsetTop
 *	2. No provision is made to align container blocks (which enclose the subject blocks)
 *	3. Does not respect max-height property (yet)
 *	4. Does not skip over invisible blocks when calculating the lowest bottom (yet)
 *	
 */
function syncBottoms(className) {
	var debug = true;
	if (debug) {
		var datetime = new Date();
		console.log('Entry at '+datetime.toLocaleString());
	}
	var lowest = 0;
	//Iterate through each element to find the lowest bottom
	jQuery(className).each(function(){	
		var o = jQuery(this);
		var bottom = o.attr('offsetTop') + o.attr('offsetHeight');
		if (bottom > lowest) lowest = bottom;
	});
	if (debug) {
		console.log('the lowest bottom found was ' + lowest + 'px.');
	}
	//Iterate through each element to lower the bottoms
	jQuery(className).each(function(){	
		var o = jQuery(this);
		var top = o.attr('offsetTop');
		var height = o.attr('offsetHeight');
		var bottom = top + height;
		if (bottom < lowest) o.height(lowest - top);
	});
	return true;
}
