/**
*	@name							Equality
*	@descripton						Equality is Jquery plugin that makes your elements look alike.
*	@version						1.1
*	@requires						Jquery 1.3.2
*
*	@author							Jan Jarfalk
*	@author-email					jan.jarfalk@unwrongest.com
*	@author-website					http://www.unwrongest.com
*
*	@licens							MIT License - http://www.opensource.org/licenses/mit-license.php
*/

(function(jQuery){ 
	jQuery.fn.extend({  
		equality: function(callback) {
	
			var collection	= [],
				position	= $(this).first().offset().top;
			
			// Takes n elements and sets the highest height to them all	
			function setHeight( elements ) {
				var max = 0;
			
				$.each( elements, function( index, element ){
					var value = $(element).height();
					if(value > max) {
						max = value;
					}
				});
				
				
				if (max > 0) {
					$( elements ).height( max );
				}
			}	
			
			$(this).each( function( index, item ) {
			
				if( $(item).offset().top !== position ){
					
					// Set height on collected elements
					setHeight( collection );
					
					// Set new position and reset collection
					position = $( item ).offset().top;
					collection.length = 0;
										
				}
				
				collection.push( item );
				
			});
			
			// Set height on the last elements
			setHeight(collection);
			
			if(callback){
				callback();
			}
        } 
    }); 
})(jQuery);
