jQuery.fn.columns = function(options) {
  // define defaults and override with options, if available
  // by extending the default settings, we don't modify the argument
	config = {
		how_many : 2,
		active_class : 'js_columns_active',
		class_prefix : 'col_' //there used to be a comma here
  };

	if (options) 
	{
	  config = jQuery.extend(config, options);
	}

	this.each(function() {
		$(this).addClass(config.active_class)

		var total = $(this).children().length;
		var rem = total % config.how_many;

		var col_counts = [];
		for(var i = 0; i < config.how_many; i++)
		{
			col_counts[i] = Math.floor(total / config.how_many) + ((rem-- > 0) ? 1 : 0);
		}

		var current = 0;
		var set = [];
		for(var i = 0; i < col_counts.length; i++)
		{
			set[i] = $(this).children().splice(current, col_counts[i]);
			current += col_counts[i];
		}

		for(var i = 0; i < set.length; i++)
		{
			$(this).append($('<div></div>').addClass(config.class_prefix + (i + 1)).append(set[i]));
		}
	});
	
	return this;
};

