// Set equal height of blocks
// by Sergei T.

(function($){
	$.fn.setEqualBlocksHeight = function(count){
		var $self = this;
		$(window).load(function(){
			if (count == 'all' || count > $self.length) count = $self.length;
			count = parseInt(count);
			if (count > 1)
			{
				$self.css({height:'auto', 'min-height':0});
				for (var i=1; i<=$self.length; i+=count)
				{
					var sameH = 0;
					for (var j=0; j<=count-1; j++)
					{
						if ($self.get(i+j-1))
						{
							var blockH = $self.eq(i+j-1).height();
							sameH = ( blockH > sameH) ? (sameH = blockH) : sameH
						}
					}
					for (var j=0; j<=count-1; j++)
					{
						if ($self.get(i+j-1))
						{
							$self.eq(i+j-1).css({'min-height': sameH});
							if ($.browser.msie && $.browser.version == '6.0') $self.eq(i+j-1).height(sameH)
						}
					}
				}
			};
			if (count == 1) $self.css({height:'auto', 'min-height':0});
			return $self
		})
	}
})(jQuery);