function $(el)
{
	if (typeof el == 'string')
		return document.getElementById(el);
	// else
	return el;
}

var BoxHeights = {
	isOpera: !!window.opera,

	equalise: function()
	{
		var heights = [];
		var maxHeight = 0;

		for (var i = 0; i < arguments.length; i++)
		{
			var el = $(arguments[i]);
			if (el)
			{
				heights[i] = this.getHeight(el);
				maxHeight = this.max(heights[i], maxHeight);
			}
		}

		maxHeight += 1;

		for (var i = 0; i < arguments.length; i++)
		{
			var el = $(arguments[i]);
			if (el)
				this.alterHeight(el, maxHeight - heights[i]);
		}
	},

	max: function()
	{
		var max = arguments[0];
		for (var i = 1; i < arguments.length; i++)
		{
			if (arguments[i] > max)
				max = arguments[i]
		}
		return max;
	},

	// get height of element[s] (including padding)
	getHeight: function()
	{
		// if more than one argument provided then get combined heights
		if (arguments.length > 1)
		{
			var height = 0;
			for (var i = 0; i < arguments.length; i++)
				height += this.getHeight(arguments[i]);
			return height;
		}
		// else
		el = $(arguments[0]);
		if (this.isOpera)
			return el.scrollHeight;
		// else
		return el.offsetHeight;
	},

	// set height of element (excluding padding)
	setHeight: function(el, height)
	{
		el = $(el);
		el.style.height = height + 'px';
	},

	// alter height of element by either number of pixels or string length (e.g. '4em')
	alterHeight: function(el, diff)
	{
		el = $(el);
		if (typeof diff == 'number')
			diff = diff + 'px';
		var height = new gslb.CssLength(diff, el);
		if (height.getPixelValue() != 0)
		{
			var paddingTop = new gslb.CssLength(this.getStyle(el, 'padding-top') || '0px', el);
			var paddingBottom = new gslb.CssLength(this.getStyle(el, 'padding-bottom') || '0px', el);

			height.addPixels(this.getHeight(el));
			height.substractPixels(paddingTop.getPixelValue());
			height.substractPixels(paddingBottom.getPixelValue());

			var pxHeight = this.max(height.getPixelValue(), 0);
			this.setHeight(el, pxHeight);
		}
	},

	// get value of computed style of element (i.e. from its class rather than just from inline style attributes)
	getStyle: function(el, strCssRule)
	{
		el = $(el);
		var strValue = '';
		if (document.defaultView && document.defaultView.getComputedStyle)
			strValue = document.defaultView.getComputedStyle(el, '').getPropertyValue(strCssRule);
		else if (el.currentStyle)
		{
			strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1) {return p1.toUpperCase();});
			strValue = el.currentStyle[strCssRule];
		}
		return strValue;
	}
}

