$(document).ready(function () {
	$('.boxes').each(function() {
		if (!$(this).hasClass('equalize')) {
			var id = $(this).attr('id');
			$(this).addClass('equalize');
			$(this).find('.box-wrapper').each(function () {
				$(this).addClass('equalize-child');
				$(this).attr('equalize_group', id);
				$(this).find('.box').addClass('equalize-add-' + id);
			});
		}
	});
	
	$('.equalize').equalize();
	
	var corner_data;
	$('.box').each(function () {
		corner_data = $(this).attr('corners');
		if ($.trim(corner_data) != '') {
			corner_data = (corner_data == 'all') ? '' : corner_data;
			$(this).corner(corner_data + ' 7px');
			$(this).parent().corner(corner_data + ' 7px');
		}
	});
});

jQuery.fn.fullHeight = function() {
	var height = $(this).outerHeight();
	var margins = parseInt($(this).css('margin-top')) + parseInt($(this).css('margin-bottom'));
	return height + margins;
}

jQuery.fn.equalize = function () {
	$(this).each (function () {
		var group = $(this).attr('id');
		var height = $(this).height();
		var diff = 0;
		var this_height = 0;
		$(".equalize-child[equalize_group='" + group + "']").each(function () {
			if ($(this).fullHeight() < height) {
				diff = height - $(this).fullHeight();
				$(this).find('.equalize-add-' + group).each(function () {
					this_height = $(this).height();
					$(this).height(this_height + diff);
				});
			}
		});
	});
}
