$(document).ready(function() {

	// Based on http://www.broken-links.com/2009/01/20/very-quick-equal-height-columns-in-jquery/
	// todo make this a function!

	var highestCol = Math.max($('#home #blocks .col-3').height());
	$('#home #blocks .col-3').height(highestCol);

	var highestCol2 = Math.max($('#eventsListFull .col-3').height());
	$('#eventsListFull .col-3').height(highestCol2);

	// Fix focus

	$('input, textarea')
		.bind('focus', function(e) {
			$(this).addClass('focus');
		})
		.bind('blur', function(e) {
			$(this).removeClass('focus');
		});
		
	$('#searchForm input[type="text"], #newsletterSignupForm input[type="text"]')
		.bind('click', function(e) {
			$(this).select();
		});

	// Preload focus image
	// from http://www.mattfarina.com/2007/02/01/preloading_images_with_jquery

	jQuery.preloadImages = function()
	{
	  for(var i = 0; i<arguments.length; i++)
	  {
	    jQuery("<img>").attr("src", arguments[i]);
	  }
	}
	
	$.preloadImages("images/loop_focus.gif");

	$('#searchForm input[type="image"]')
		.bind('click focus mouseover', function(e) {
			$(this).attr('src', '/modules/core/layout/images/loop_focus.gif');
		})
		.bind('blur mouseout', function(e) {
			$(this).attr('src', '/modules/core/layout/images/loop.gif');
		});

	// Some crazy layout tricks on events page
	
	// var titleHeight = $('#events #title').height();
	// var secondaryHeight = $('#eventsSecondary .colAbsolute').height()
	// var topValue = titleHeight - secondaryHeight
	// 
	// $('#eventsSecondary .colAbsolute').css('top', topValue)
	
	// Fix the a/img problem
	$("img").each(function() {
		var parentTag = $(this).parent().get(0).tagName;
		if (parentTag == 'A') {
			$(this).parent().addClass('noBorder');
		};
	});

});
