(function($) {
	$(window).ready(function() {
		
		var e = $('.contentLeft .subBlock');
		// if there is only one block within the leftcolumn
		if (e.length == 1) {
			var content = e.find('.content-block-inner');
			if (content.length) {
				// couldn't get it exactly right so please tell me if you know how to calculate it --ew
				var heightRightCol = $('.contentRight').height();
				if (heightRightCol > $('.contentLeft').height()) {
					while (heightRightCol > $('.contentLeft').height()) {
						content.height(content.height() + 10);
					}
					while ($('.contentLeft').height() > heightRightCol) {
						content.height(content.height() - 1);
					}
				}
			}
		}
		
		
		var blocks = $('.contentLeft .contentBlock');
		var i = 0;
		$.each(blocks,function() {
			if (i++ % 2 == 0) {
				newElement = document.createElement('div');
				$(newElement).addClass('block-wrapper');
				$(this).before(newElement);
				$(newElement).append($(this));
			} else {
				$(newElement).append($(this));
			}
			
		});
		
		var wrappers = $('.contentLeft .block-wrapper');
		$.each(wrappers,function() {
			wrapper = $(this);
			var currentTallest = 0;
			$.each($(this).children('.contentBlock'),function(){
				if ($(this).children('.middle').height() > currentTallest) { 
					currentTallest = $(this).children('.middle').height();
				}
			});
			$(wrapper).find('.middle').css('height',currentTallest + 'px');
		});
	});
})(jQuery);
