/*-------------------------------------------------------------------- 
 * JQuery Plugin: "EqualHeights"
 * by:	Scott Jehl, Todd Parker, Maggie Costello Wachs (http://www.filamentgroup.com)
 *
 * Copyright (c) 2008 Filament Group
 * Licensed under GPL (http://www.opensource.org/licenses/gpl-license.php)
 *
 * Description: Compares the heights or widths of the top-level children of a provided element 
 		and sets their min-height to the tallest height (or width to widest width). Sets in em units 
 		by default if pxToEm() method is available.
 * Dependencies: jQuery library, pxToEm method	(article: 
		http://www.filamentgroup.com/lab/retaining_scalable_interfaces_with_pixel_to_em_conversion/)							  
 * Usage Example: $(element).equalHeights();
  		Optional: to set min-height in px, pass a true argument: $(element).equalHeights(true);
 * Version: 2.0, 08.01.2008
--------------------------------------------------------------------*/

function equalHeight(group) {
	tallest = 0;
	group = $(group);
	group.each(function() {
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
}

function loadAudio(target, file){
	var params = {
		allowfullscreen: true,
		allowscriptaccess: 'always',
		wmode: 'opaque'
	};
	var vars = {
		file: file
	};
	swfobject.embedSWF("/flash/lib/jwplayer/player.swf", target, "340", "24", "9.0.0", false, vars, params);
}

function sendMailTo(name, company, domain) {
  locationstring = 'mai' + 'lto:' + name + '@' + company + '.' + domain;
  window.location.replace(locationstring);
}

$(document).ready(function(){

	// Equal heights

	equalHeight('div.equalHeight1');
	equalHeight('div.equalHeight2');
	
	// Animate to top
	$('.toTop').click(function(){
		$('html, body').animate({scrollTop: '0px'}, 400);
		return false;
	});
	
	// Loader
	
	if($('.loader').length) {
		var offset = 62;
		var speed = 30;
		var frames = 10;
		var position = 0;
		var direction = 1;
		
		function moveImage(){
			$('.loader').css("background-position","0px "+( offset*-position)+"px");
			position += direction;
			if( position == frames || position == 0 ) direction = -direction;
			setTimeout( moveImage, speed );
		}
		
		setTimeout( moveImage, speed );

	}

	// All external links in new window //
	$("a[href*='http://']:not([href*='"+location.hostname+"']),[href*='https://']:not([href*='"+location.hostname+"'])")
	.addClass("external")
	.attr("target","_blank")
	.attr("title","Opens new window");

});
