/*

Script to resize elements to make them appear the same height.

Requires:
/common/scripts/portable/addEventListener.js
/common/scripts/findPosition.js

*/

function mysortfn(a,b) //sort multidimensional array by 4th dimension
{
	if (a[3]>b[3]) return -1;
	if (a[3]<b[3]) return 1;
	return 0;
}

function setMeasurements(elmStats)
{
	var largest = elmStats[0][3];
	for (i=1; i<elmStats.length; i++) { //tweak elements except one furthest down page
		var difference = largest - elmStats[i][3];
		elmStats[i][0].style.paddingBottom = difference + 'px';
		elmStats[i][0].style.marginBottom = '0px';
	}
}

function getMeasurements(elmids)
{
	var elmStats = new Array();
	for (i=0; i<elmids.length; i++) { //find element stats - position, height, bottom margin
		var elm = document.getElementById(elmids[i]);
		var bottom = findPosition(elm)[1] + elm.offsetHeight;
		elmStats[i] = new Array(elm, findPosition(elm)[1], elm.offsetHeight, bottom);
	}
	elmStats.sort(mysortfn); //sort array by element with bottom margin furthest down page
	setMeasurements(elmStats);
}

function trigger()
{
	if (!document.getElementById || typeof document.body.offsetHeight == 'undefined') { //DOM feature sniffing
		return;
	}
	window.setTimeout('resize()', 100); //timeout to deal with IE JS minmax resizing - dirty hack
}

