/**
 * Make column heights match
 * @param elements array of elements to match heights on
 */

window.addEvent('domready', function(){
	/*
	 * Fixe the height of slideshows so that
	 * IE6 doesn't generate columns too long
	 */
	var ie6Fix = function() {
		if(window.ie6) {
			//Make a list of slides
			var slides = $$('#content .slideElement');

			slides.each(function(el,i) {
				var slideshow = el.getParent();
				var slideshowsize = slideshow.getSize();
				var slidesize = el.getSize();
				slideshow.setStyle('height', slidesize.y + 'px');
				slideshow.setStyle('overflow', 'hidden');
			});
		}
		this.callChain();
	};

	/*
	 * Resizes the heights of the columns to match the longest
	 */
	var columnFix = function() {
		//Make a list of columns
		var columns = $$('#left_column', '#content', '.article_column', '#content_search');
		//Find the longest element
		var compare_height = 0;

		columns.each(function(el,i) {
			var dims = el.getSize();
			
			if((dims.size.y) > compare_height) {
				compare_height =  (dims.size.y);
			}
		});
			
		//Set all the elements to match the longest length
		columns.each(function(el,i) {
			var padding = el.getStyle('padding-bottom');
			var padding = parseFloat(padding);
			el.setStyle('height',(compare_height - padding)+'px');
		});
		
		this.callChain();
	};

	//Setup the actions to perform
	var columnEvents = new Chain();
	columnEvents.chain(ie6Fix);
	columnEvents.chain(columnFix);

	//Fire the whole chain of fixes
	columnEvents.callChain();
});
