(function(){var MIN_COLS=3,COL_WIDTH=parseInt($(".item").css("width")),PADDING=parseInt($(".item").css("margin-right")),X=PADDING,Y=(PADDING*2)+64;$(".item").css("position","absolute");$(".item").css("left",X);$(".item").css("top",Y);$(document).ready(function(){arrange();});$(window).resize(function(){arrange();});arrange=function(){var width=$("body").innerWidth(),columns=Math.max(MIN_COLS,parseInt(width/(COL_WIDTH+PADDING))),actual_columns=0,column=1,row=1,x=X,y=Y,next_row=false,prev_x,_i,first_item,this_item,delay=100;$(".item").each(function(i){this_item=$(this);if(column<=columns&&row>1){current=$(this);for(i=0;i<columns;i++){current=current.prev();if(!current){current=null;break;}}if(current){y=parseInt(current.css("top"))+parseInt(current.css("height"))+PADDING;}}if((x+parseInt($(this).css("width"))-PADDING)>width&&column>MIN_COLS){x=X;column=1;next_row=true;y=parseInt(first_item.css("top"))+parseInt(first_item.css("height"))+PADDING;first_item=null;row++;if(columns!=actual_columns){columns=actual_columns;}}else{actual_columns++;}if(!first_item){first_item=$(this);}$(this).css("left",x+"px");$(this).css("top",y+"px");if($(this).css("display")=="none"){$(this).delay(delay).fadeIn(250);delay+=50;}x+=parseInt($(this).css("width"))+PADDING;column+=parseInt($(this).css("width"))/(COL_WIDTH+PADDING);});if($("#bottom").length){var first_item=$(".item").last();while(first_item.length){if(parseInt(first_item.css("left"))==X)break;first_item=first_item.prev();}$("#bottom").css("position","absolute");$("#bottom").css("left",X+"px");$("#bottom").css("top",parseInt(first_item.css("top"))+parseInt(first_item.css("height"))+PADDING+"px");}};}());
