/**
 * jQuery-Plugin "ezColumns"
 * 
 * @version: 1.0.0, 1.07.2011
 * 
 * @author: Andres Vidal
 *          code@andresvidal.com
 *          http://www.andresvidal.com/labs/ezcolumns.html
 *
 * Instructions: Pass in a jQuery selector to the parent of the children to organize in columns.
 * When using UL LI, a {target} and {colWrapper} may be defined to properly set up the columns.
 *
 * @example: JavaScript: $("ul.list").ezColumns({colWrapper: '<ul class="col"></ul>', target: $("div.countries")});
 * HTML: <div class="countries"></div> <ul class="list"> <li>example1</li><li>example2</li> <li>example3</li> ... </ul>
 *
 * @colWrapper    string or DOM object  The HTML wrapper for each column. Default: <div class="col"></div>
 * @target        DOM object            The target element to append the columns. Default: plugin selector
 * @groups        DOM object collection A collection of DOM objects to organize into columns. Default: plugin selector children
 * @columns       string                The max number of columns to use. Default: 3
 * @callback      function              A function to run after the plugin finishes appending all elements to the DOM.
 * 
 */

(function(b){b.fn.ezColumns=function(a){b(this).data("groups")||b(this).data("groups",b(this).children().remove());var c=b(this).data("groups").clone(),a=jQuery.extend({colWrapper:'<div class="col"></div>',target:this,groups:false,columns:3,callback:function(){}},a);a.groups=a.groups?a.groups:c;a.columns=a.columns>a.groups.length?a.groups.length:a.columns;a.perColumn=Math.floor(a.groups.length/a.columns);a.mod=a.groups.length%a.columns;b(a.target).empty();for(c=0;c<a.columns;c++){var d;d=c<=a.mod-
1?a.groups.splice(0,a.perColumn+1):a.groups.splice(0,a.perColumn);b(a.target).append(b(a.colWrapper).append(d))}a.callback.call(this);return this}})(jQuery);
