/** @package eFocus js lib */

/**
 * escrips.js - default scripts commonly used
 *
 * @author Rocco Janse <rocco@efocus.nl>
 * @since 1.0, 14 aug, 2009
 * @copyright eFocus
 * @package eFocus js lib
 * @uses MooTools 1.2.2 More <http://www.mootools.net>
 */

/**
 * Opens external links without the target attribute
 * 
 * @author Ralph Meeuws <ralph.meeuws@efocus.nl>
 * @author Rocco Janse <rocco@efocus.nl>
 * @since 1.0, 14 aug, 2009
 * @return void
 */
 
function fixExternalLinks() {
	var arrExternalLinks = $$('a.external');
	if (arrExternalLinks.length == 0) return;
	
	arrExternalLinks.each(function(link) {
		link.addEvents({
			'click': function(event) {
				event.stop();
				window.open(this.get('href'));
			}   
		});
	});
}

/**
 * makes multiple different elements all the same height,
 * assuming the height of the highest element
 *
 * @param arElements, Array of DOM elements to compare fix height
 *
 * @author Klaas Dieleman <klaas{AT}efocus.nl>
 *
 * @return h, height of highest element in px
 */

function makeEqualHeight(arElements) {
	var h = 0;
	
	for(var i = 0 ; i < arElements.length ; i++) {
		if(arElements[i].getSize().y > h) h = arElements[i].getSize().y;
	}
	
	arElements.each(function(item) {
		var ch = 0;
		var ah = item.getStyle('padding-top').toInt();
		ah += item.getStyle('padding-bottom').toInt();
		ah += item.getStyle('border-top-width').toInt();
		ah += item.getStyle('border-bottom-width').toInt();
		ch = h - ah;
		item.setStyle('height', ch);
	});
	
	return h;
}
