/*!
* Justified Gallery - v3.2.0
* http://miromannino.com/projects/justified-gallery/
* Copyright (c) 2014 Miro Mannino
* Licensed under the MIT license.
*/
!function(a){a.fn.justifiedGallery=function(b){function c(a,b,c){var d;return d=a>b?a:b,100>=d?c.settings.sizeRangeSuffixes.lt100:240>=d?c.settings.sizeRangeSuffixes.lt240:320>=d?c.settings.sizeRangeSuffixes.lt320:500>=d?c.settings.sizeRangeSuffixes.lt500:640>=d?c.settings.sizeRangeSuffixes.lt640:c.settings.sizeRangeSuffixes.lt1024}function d(b){var c=a(b.currentTarget).find(".caption");b.data.settings.cssAnimation?c.addClass("caption-visible").removeClass("caption-hidden"):c.stop().fadeTo(b.data.settings.captionSettings.animationDuration,b.data.settings.captionSettings.visibleOpacity)}function e(b){var c=a(b.currentTarget).find(".caption");b.data.settings.cssAnimation?c.removeClass("caption-visible").removeClass("caption-hidden"):c.stop().fadeTo(b.data.settings.captionSettings.animationDuration,b.data.settings.captionSettings.nonVisibleOpacity)}function f(b,f,g,h,i,j,k){var l=b.find("img");l.css("width",h),l.css("height",i),l.css("margin-left",-h/2),l.css("margin-top",-i/2),b.width(h),b.height(j),b.css("top",g),b.css("left",f);var m=l.attr("src"),n=m.replace(k.settings.extension,"").replace(k.usedSizeRangeRegExp,"")+c(h,i,k)+m.match(k.settings.extension)[0];l.one("error",function(){l.attr("src",l.data("jg.originalSrc"))});var o=function(){m!==n&&l.attr("src",n)};k.settings.cssAnimation?(b.addClass("entry-visible"),o()):b.stop().fadeTo(k.settings.imagesAnimationDuration,1,o);var p=b.data("jg.captionMouseEvents");if(k.settings.captions===!0){var q=b.find(".caption");if(0===q.length){var r=l.attr("alt");"undefined"==typeof r&&(r=b.attr("title")),"undefined"!=typeof r&&(q=a('
'+r+"
"),b.append(q))}0!==q.length&&(k.settings.cssAnimation||q.stop().fadeTo(k.settings.imagesAnimationDuration,k.settings.captionSettings.nonVisibleOpacity),"undefined"==typeof p&&(p={mouseenter:d,mouseleave:e},b.on("mouseenter",void 0,k,p.mouseenter),b.on("mouseleave",void 0,k,p.mouseleave),b.data("jg.captionMouseEvents",p)))}else"undefined"!=typeof p&&(b.off("mouseenter",void 0,k,p.mouseenter),b.off("mouseleave",void 0,k,p.mouseleave),b.removeData("jg.captionMouseEvents"))}function g(a,b){var c,d,e,f,g,h,i=!0,j=0,k=a.galleryWidth-(a.buildingRow.entriesBuff.length-1)*a.settings.margins,l=k/a.buildingRow.aspectRatio,m=a.buildingRow.width/k>a.settings.justifyThreshold;if(b&&"hide"===a.settings.lastRow&&!m){for(c=0;ch)&&(j=h);return a.settings.fixedHeight&&j>a.settings.rowHeight&&(j=a.settings.rowHeight),j}function h(a){a.lastAnalyzedIndex=-1,a.buildingRow.entriesBuff=[],a.buildingRow.aspectRatio=0,a.buildingRow.width=0,a.offY=0,a.firstRowFlushed=!1}function i(a,b){var c,d,e,h=0;if(e=g(a,b),b&&"hide"===a.settings.lastRow&&-1===e)return a.buildingRow.entriesBuff=[],a.buildingRow.aspectRatio=0,void(a.buildingRow.width=0);a.settings.maxRowHeight>0&&a.settings.maxRowHeight=b.entries.length-1;var h=b.galleryWidth-(b.buildingRow.entriesBuff.length-1)*b.settings.margins,j=g.data("jg.imgw")/g.data("jg.imgh");if(h/(b.buildingRow.aspectRatio+j)=b.yield.every))return void n(b,c);b.buildingRow.entriesBuff.push(f),b.buildingRow.aspectRatio+=j,b.buildingRow.width+=j*b.settings.rowHeight,b.lastAnalyzedIndex=e}else if("error"!==g.data("jg.loaded"))return}b.buildingRow.entriesBuff.length>0&&i(b,b.firstRowFlushed),b.spinner.active&&(b.spinner.active=!1,b.$gallery.height(b.$gallery.height()-b.spinner.$el.innerHeight()),b.spinner.$el.detach(),l(b.spinner)),m(b),b.$gallery.trigger(c?"jg.resize":"jg.complete")}function p(a){function b(b){if("string"!=typeof a.settings.sizeRangeSuffixes[b])throw"sizeRangeSuffixes."+b+" must be a string"}function c(a,b){if("string"==typeof a[b]){if(a[b]=parseFloat(a[b],10),isNaN(a[b]))throw"invalid number for "+b}else{if("number"!=typeof a[b])throw b+" must be a number";if(isNaN(a[b]))throw"invalid number for "+b}}if("object"!=typeof a.settings.sizeRangeSuffixes)throw"sizeRangeSuffixes must be defined and must be an object";if(b("lt100"),b("lt240"),b("lt320"),b("lt500"),b("lt640"),b("lt1024"),c(a.settings,"rowHeight"),c(a.settings,"maxRowHeight"),c(a.settings,"margins"),"nojustify"!==a.settings.lastRow&&"justify"!==a.settings.lastRow&&"hide"!==a.settings.lastRow)throw'lastRow must be "nojustify", "justify" or "hide"';if(c(a.settings,"justifyThreshold"),a.settings.justifyThreshold<0||a.settings.justifyThreshold>1)throw"justifyThreshold must be in the interval [0,1]";if("boolean"!=typeof a.settings.cssAnimation)throw"cssAnimation must be a boolean";if(c(a.settings.captionSettings,"animationDuration"),c(a.settings,"imagesAnimationDuration"),c(a.settings.captionSettings,"visibleOpacity"),a.settings.captionSettings.visibleOpacity<0||a.settings.captionSettings.visibleOpacity>1)throw"captionSettings.visibleOpacity must be in the interval [0, 1]";if(c(a.settings.captionSettings,"nonVisibleOpacity"),a.settings.captionSettings.visibleOpacity<0||a.settings.captionSettings.visibleOpacity>1)throw"captionSettings.nonVisibleOpacity must be in the interval [0, 1]";if("boolean"!=typeof a.settings.fixedHeight)throw"fixedHeight must be a boolean";if("boolean"!=typeof a.settings.captions)throw"captions must be a boolean";if(c(a.settings,"refreshTime"),"boolean"!=typeof a.settings.randomize)throw"randomize must be a boolean"}var q={sizeRangeSuffixes:{lt100:"_t",lt240:"_m",lt320:"_n",lt500:"",lt640:"_z",lt1024:"_b"},rowHeight:120,maxRowHeight:0,margins:1,lastRow:"nojustify",justifyThreshold:.75,fixedHeight:!1,captions:!0,cssAnimation:!1,imagesAnimationDuration:300,captionSettings:{animationDuration:500,visibleOpacity:.7,nonVisibleOpacity:0},rel:null,target:null,extension:/\.[^.]+$/,refreshTime:250,randomize:!1};return this.each(function(c,d){var e=a(d);e.addClass("justified-gallery");var f=e.data("jg.context");if("undefined"==typeof f){if("undefined"!=typeof b&&null!==b&&"object"!=typeof b)throw"The argument must be an object";var g=a('
');f={settings:a.extend({},q,b),imgAnalyzerTimeout:null,entries:null,buildingRow:{entriesBuff:[],width:0,aspectRatio:0},lastAnalyzedIndex:-1,firstRowFlushed:!1,"yield":{every:2,flushed:0},offY:0,spinner:{active:!1,phase:0,timeslot:150,$el:g,$points:g.find("span"),intervalId:null},checkWidthIntervalId:null,galleryWidth:e.width(),$gallery:e},e.data("jg.context",f)}else"norewind"===b||(f.settings=a.extend({},f.settings,b),h(f));if(p(f),f.entries=e.find("> a, > div").toArray(),0!==f.entries.length){f.settings.randomize&&(f.entries.sort(function(){return 2*Math.random()-1}),a.each(f.entries,function(){a(this).appendTo(e)})),f.usedSizeRangeRegExp=new RegExp("("+f.settings.sizeRangeSuffixes.lt100+"|"+f.settings.sizeRangeSuffixes.lt240+"|"+f.settings.sizeRangeSuffixes.lt320+"|"+f.settings.sizeRangeSuffixes.lt500+"|"+f.settings.sizeRangeSuffixes.lt640+"|"+f.settings.sizeRangeSuffixes.lt1024+")$"),f.settings.maxRowHeight>0&&f.settings.maxRowHeight