$(document).ready(function(){
	// Photo cycles for the frontpage
	$('#photo1').cycle({ delay:  4500, speed:  2000 });	
	$('#photo2').cycle({ delay:  1500, speed:  2000 });	
	$('#photo3').cycle({ delay:  3000, speed:  2000 });	
	
	// Project photos
	$('#project_photo').cycle({ 
		prev: "#prev",
		next: "#next",
		delay: 4000,
		speed: 1500,
		pause: 1
	});
	
	// Contact form submission
	$('#contactForm').bind('submit', function() {
		$(this).ajaxSubmit({
			target: '#output',
			beforeSubmit: showSending,
			success: showResponse
		});
		return false;
	});
	
	// Table striping
	$("table tr").mouseover(function(){
		$(this).addClass("over");
	}).mouseout(function(){
		$(this).removeClass("over");
	});
	$("table tr:even").addClass("alt");
	
	// Ensure equal column length
	smartColumns('projects','project-wrap');

	$(window).resize(function () { 
		smartColumns('projects','project-wrap');
	});
});

function smartColumns(col1, col2) {

	var c1 = $('#'+col1).height();
	var c2 = $('#'+col2).height();
		
	if ( c2 > c1 ) {
		$('#'+col1).css('height', c2);		
	}		
}

function showResponse(responseText, statusText){
	$('#loading').hide();
	$('#output').show();
	$('#sendContactEmail').attr("value","All Done.")
}

function showSending(){
	$('#sendContactEmail').attr("disabled",true);
	$('#sendContactEmail').attr("value","Sending...")
	$('#loading').show();
}
