(function($){

$.fn.jcolumns = function(options) {
	
	var defaults = {
		// class to apply
		columnClass: "section",
		// number of columns to create
		columnCount: 2,
		// counter
		counter: 0
	};
	
	var options = $.extend(defaults, options);

    return this.each(function() {
	
	    var $inBox = $(this);
		var $cache = $('<div></div>');
		var maxHeight = $(this).height();
		
		if(options.columnCount > 0)
		{
			$cache.append($(this).children().clone());
		    $inBox.empty();
			jcolumnIt();
		}
		
		function jcolumnIt()
		{
			if(options.counter < options.columnCount)
			{
				//Create a new column
				$section = $('<div class="' + options.columnClass + '" style="height:auto"></div>');
				$inBox.parent().append($section);

				//For each
				$cache.children().each(
					function()
					{
						$section.append($(this));
						if($section.height() > maxHeight)
						{
							$cache.prepend($(this));
							options.counter++;
							jcolumnIt();
						}
					}
				);
			}
			$inBox.remove();
		}
    });
 };
})(jQuery);