/*
 * jLayout Grid Layout - JavaScript Layout Algorithms v0.4
 *
 * Licensed under the new BSD License.
 * Copyright 2008-2009, Bram Stein
 * All rights reserved.
 */
(function(){jLayout=typeof jLayout==="undefined"?{}:jLayout;jLayout.grid=function(a,e){var d=e||{},b={};d.hgap=a.hgap||0;d.vgap=a.vgap||0;d.items=a.items||[];d.columns=a.columns||d.items.length;d.rows=a.rows||0;if(d.rows>0){d.columns=Math.floor((d.items.length+d.rows-1)/d.rows)}else{d.rows=Math.floor((d.items.length+d.columns-1)/d.columns)}b.items=function(){var f=[];Array.prototype.push.apply(f,d.items);return f};b.layout=function(k){var m,l,h=k.insets(),g=h.left,o=h.top,n=(k.bounds().width-(h.left+h.right)-(d.columns-1)*d.hgap)/d.columns,f=(k.bounds().height-(h.top+h.bottom)-(d.rows-1)*d.vgap)/d.rows;for(m=0,l=1;m<d.items.length;m+=1,l+=1){d.items[m].bounds({x:g,y:o,width:n,height:f});if(d.columns<=d.rows){if(l>=d.columns){o+=f+d.vgap;g=h.left;l=0}else{g+=n+d.hgap}}else{if(l>=d.rows){g+=n+d.hgap;o=h.top;l=0}else{o+=f+d.vgap}}d.items[m].doLayout()}return k};function c(f){return function(j){var k=0,l=0,g=0,m,h=j.insets();for(;k<d.items.length;k+=1){m=d.items[k][f+"Size"]();l=Math.max(l,m.width);g=Math.max(g,m.height)}return{width:h.left+h.right+d.columns*l+(d.columns-1)*d.hgap,height:h.top+h.bottom+d.rows*g+(d.rows-1)*d.vgap}}}b.preferred=c("preferred");b.minimum=c("minimum");b.maximum=c("maximum");return b}})();
