// Custom JScripts for www.surf-magazin.de

/*
 * Create the namespace
 */

// Declare global symbol
var surf;

// If it is undefined yet, make it an object
if (!surf) surf = {};

// Add events for all pages
window.addEvent('load', function() { surf.setMultiColRowHeight(); })

// Hack for IE <noscript> visibility
window.addEvent('domready', function() {
	$('noscript').setStyle('display', 'none');
});

surf.setMultiColRowHeight = function() 
{
	var twoColRows = $$('div.twoCols');
	var threeColRows = $$('div.threeCols');

	if (twoColRows.length > 0) {
		
		// Walk through every two column row
		twoColRows.each(function(row, index) {
			items = row.getElements('.box');
			adjustHeightOf(items);
		});
	}
	
	if (threeColRows.length > 0) {
		
		// Walk through every three column row
		threeColRows.each(function(row, index) {
			items = row.getElements('.box');
			adjustHeightOf(items);
		});
	}
	
}

/**
 * Sets an array of elements to the same height.
 *
 * @param {Array} items The array of elements.
 */ 	
function adjustHeightOf(items) {
	
	//alert('New row');
	
	var highest = 0;
	
	// Get size of highest element
	items.each(function(item, index) {
		var size = item.getFirst().getSize();
		var paddingTop = item.getFirst().getStyle('padding-top').toInt();
		var paddingBottom = item.getFirst().getStyle('padding-bottom').toInt();
		var offset = paddingTop + paddingBottom;
		var height = size.y - offset;
		//alert($(item).get('class') + ' ' + height);
		if (height > highest) {
			highest = height;
		}
	});
	
	// Set size of highest element
	items.each(function(item, index) {
		item.getFirst().setStyle('height', highest + 'px');
	});
	
}
