/*
 * jLayout Flex Grid Layout - JavaScript Layout Algorithms v0.4
 * Based on: http://www.javaworld.com/javaworld/javatips/jw-javatip121.html
 *
 * Licensed under the new BSD License.
 * Copyright 2008-2009, Bram Stein
 * All rights reserved.
 */
(function(){jLayout=typeof jLayout==="undefined"?{}:jLayout;if(typeof jLayout.grid!=="undefined"){jLayout.flexGrid=function(a){var e={},b=this.grid(a,e);function d(g,f){var h=0;for(;h<f;h+=1){g[h]=0}return g}function c(f){return function(j){var m=0,g=0,p=0,o=0,k=0,q=d([],e.columns),n=d([],e.rows),s,l=j.insets();for(m=0;m<e.items.length;m+=1){g=m/e.columns;p=m%e.columns;s=e.items[m][f+"Size"]();if(q[p]<s.width){q[p]=s.width}if(n[g]<s.height){n[g]=s.height}}for(m=0;m<e.columns;m+=1){o+=q[m]}for(m=0;m<e.rows;m+=1){k+=n[m]}return{width:l.left+l.right+o+(e.columns-1)*e.hgap,height:l.top+l.bottom+k+(e.rows-1)*e.vgap}}}b.preferred=c("preferred");b.minimum=c("minimum");b.maximum=c("maximum");b.layout=function(g){var k=0,o=0,f=0,p=b.preferred(g),u=g.bounds().width/p.width,m=g.bounds().height/p.height,t=d([],e.columns),l=d([],e.rows),j=g.insets(),s=j.left,q=j.top,n;for(k=0;k<e.items.length;k+=1){f=k/e.columns;o=k%e.columns;n=e.items[k].preferredSize();n.width=u*n.width;n.height=m*n.height;if(t[o]<n.width){t[o]=n.width}if(l[f]<n.height){l[f]=n.height}}for(o=0;o<e.columns;o+=1){for(f=0,q=j.top;f<e.rows;f+=1){k=f*e.columns+o;if(k<e.items.length){e.items[k].bounds({x:s,y:q,width:t[o],height:l[f]});e.items[k].doLayout()}q+=l[f]+e.vgap}s+=t[o]+e.hgap}return g};return b}}})();
