var def_text = 'Search';

$(document).ready(function()
{
	$('#search .text').focus(function()
	{
		if($(this).attr('value') == def_text) $(this).attr('value','');
	});
	$('#search .text').blur(function()
	{
		if($(this).attr('value') == '') $(this).attr('value',def_text);
	});
	
	$('.row').each(function(){
		$(this).find('.client-logo').equalHeights();
		//$('.client-logo img').vAlign();
	});
	
	$('.news-item').each(function(){
		var h = $(this).find('.latest-news-text').height();
		$(this).find('.latest-news-image table td').height(h);
	});
	
	$('#thumbnails .thumb.full img').each(function(){
		$(this).wrap('<table style="height:150px;"><tr><td></td></tr></table>');
	});
	
	set_external_links();
	
	// Ensure requested page link is highlighted
	var host = window.location.protocol+'//'+window.location.host;
	var uri_array = document.URL.replace(host,'').split('/');
	
	var uri = '';
	
	for(var i in uri_array){
		uri = uri + uri_array[i] + '/';
		uri = uri.replace("//","/");
		
		var current_link = $('#nav a[href="'+uri+'"],#nav a[href="'+host+uri+'"]');
	
		if(current_link.length){
			$('#nav .selected').removeClass('selected');
			current_link.parent('li').addClass('selected');
		}
	}
	
	
	
});

window.onload=function() {
	
	var highest = 0;
	$('.row').each(function(){
		$(this).find('.client-logo img').each(function() {
					var thisHeight = $(this).height();								 
					if(thisHeight > highest)
					{
						highest = thisHeight;
					}
		});
		$(this).find('.client-logo').height(highest + 10);
		$(this).find('.client-logo img').each(function() {
			var ah = $(this).height();
			var mh = (highest - ah) / 2;
			$(this).css('margin-top', mh);
		});
		highest = 0;
	});
	
};

function set_external_links() {
	$('a[href^=http]').not('a[href^="'+window.location.protocol+'//'+window.location.host+'"]').click(function(e){
		e = window.event || e; if(e.preventDefault) e.preventDefault(); else e.returnValue = false;
    window.open(this.href); return false;
	});
}
