$.fn.sameHeights = function() {

$(this).each(function(){
var tallest = 0;

$(this).children().each(function(i){
if (tallest < $(this).height()) { tallest = $(this).height(); }
});
$(this).children().css({'height': tallest});
});
return this;
};

$(function(){
	
	$whatBG = $('#bg').attr('src');
	$('#bg').remove()
	$.backstretch($whatBG, {speed: 1000});
	
	$projectArray = [];
	$('#projectGallery img').each(function() {
		$projectArray.push($(this).attr('src'));
	});
	$('#projectGallery img').remove();
	$.backstretch($projectArray[0], {speed: 1000});
	
	$('.imageNav a').click(function(e) {
		e.preventDefault();
		$whatIndex = $(this).parent().index();
		log($whatIndex);
		$('.imageNav .active').removeClass('active');
		$(this).parent().addClass('active');
		$('#backstretch').remove();
		$.backstretch($projectArray[$whatIndex]);
	});
	
	
	$('.equaliser').sameHeights();
	
	$(".polaroid").each( function() {
		var rNum = (Math.random()*8)-4;  
		$(this).css( {
			'-webkit-transition': 'all 0.2s ease-in-out',
			'-moz-transition': 'all 0.2s ease-in-out',
			'-o-transition': 'all 0.2s ease-in-out',
			'-ms-transition': 'all 0.2s ease-in-out',
			'transition': 'all 0.2s ease-in-out',
			'-webkit-transform': 'rotate('+rNum+'2deg)',
			'-moz-transform': 'rotate('+rNum+'2deg)',
			'-o-transform': 'rotate('+rNum+'2deg)',
			'-ms-transform': 'rotate('+rNum+'2deg)',
			'transform': 'rotate('+rNum+'2deg)'
		});
		$(this).hover(function() {
			$(this).css( {
				'-webkit-transform': 'rotate(0deg)',
				'-moz-transform': 'rotate(0deg)',
				'-o-transform': 'rotate(0deg)',
				'-ms-transform': 'rotate(0deg)',
				'transform': 'rotate(0deg)'
			});
		}, function() {
			$(this).css( {
				'-webkit-transform': 'rotate('+rNum+'2deg)',
				'-moz-transform': 'rotate('+rNum+'2deg)',
				'-o-transform': 'rotate('+rNum+'2deg)',
				'-ms-transform': 'rotate('+rNum+'2deg)',
				'transform': 'rotate('+rNum+'2deg)'
			});
		});
	});
	
	$('.panel.home').append('<a class="close" href="#">Close</a>');
	$('.panel.home .close').click(function(e) {
		e.preventDefault();
		$(this).parent().slideUp(500, function() {
			$('.panel.home').before('<a class="revealInfo" href="#"><span>Show info</span></a>');
			$('.revealInfo').hide().slideDown().click(function(e) {
				e.preventDefault();
				$(this).slideUp(500, function() {
					$(this).remove();
					$('.panel.home').slideDown(500);
				});
			});
		});
	});
});

