!function(t,i,h,e){"use strict";function o(i,h){this.element=i,this.$el=t(i),this._name=s,this.init(h)}var s="justifiedImages";o.prototype={defaults:{template:function(t){return'
'},appendBlocks:function(){return[]},rowHeight:150,maxRowHeight:350,handleResize:!1,margin:1,imageSelector:"image-thumb",imageContainer:"photo-container"},init:function(i){this.options=t.extend({},this.defaults,i),this.displayImages(),this.options.handleResize&&this.handleResize()},getBlockInRow:function(t){for(var i=this.options.appendBlocks(),h=0;ho;){var w={width:0,photos:[]},u=0,v=this.getBlockInRow(a.length+1);for(v&&(w.width+=v.width,f+=v.width);f+h[o+u]/2<=m*(a.length+1)&&s>o+u;)f+=h[o+u],w.width+=h[o+u],w.photos.push({width:h[o+u],photo:n[o+u]}),u++;o+=u,a.push(w)}console.log(a.length,a);for(var y=0;ythis.options.maxRows)break;y===a.length-1&&(R=!0),f=-1*d;var I=this.getBlockInRow(R?-1:e),x=l;I&&(x-=I.width,f=0);var b=x/w.width,u=w.photos.length,k=Math.min(Math.floor(c*b),parseInt(this.options.maxRowHeight,10));b=k/this.options.rowHeight;var H=t("",{"class":"picrow"});H.height(k+d),g.append(H);for(var M="",B=0;Bf;){var S=H.find("."+this.options.imageContainer+":nth-child("+(C+1)+")"),$=S.find("."+this.options.imageSelector);$.width($.width()+1),C=(C+1)%u,f++}for(C=0;f>x;){var P=H.find("."+this.options.imageContainer+":nth-child("+(C+1)+")"),_=P.find("."+this.options.imageSelector);_.width(_.width()-1),C=(C+1)%u,f--}}else if(x-f>.05*x)for(var O=x-f,W=0,q=H.find("."+this.options.imageContainer),A=0,N=0;N",{"class":this.options.imageContainer+" added-block",css:{width:I.width,height:k},html:I.html}).appendTo(H)}else H.remove()}},renderPhoto:function(i,h,e){var o={},s;return s=t.extend({},i,{src:h.src,displayWidth:h.width,displayHeight:h.height,marginRight:e?0:this.options.margin}),this.options.dataObject?o[this.options.dataObject]=s:o=s,this.options.template(o)},handleResize:function(){},refresh:function(i){this.options=t.extend({},this.defaults,i),this.$el.empty(),this.displayImages()}},t.fn[s]=function(i){var h=arguments,e;return this.each(function(){var n=t(this),a=t.data(this,"plugin_"+s),r="object"==typeof i&&i;a?"string"==typeof i?e=a[i].apply(a,Array.prototype.slice.call(h,1)):a.refresh.call(a,r):n.data("plugin_"+s,a=new o(this,r))}),e||this}}(jQuery,window,document);