var MoodboardEl=function(t){this.el=t,this.initialize()};MoodboardEl.prototype.initialize=function(){if(this.el){var t=this.el.getAttribute("src"),o=new Image;o.onload=function(){this.originalWidth=o.width,this.originalHeight=o.height}.bind(this),o.src=t}},MoodboardEl.prototype.position=function(t,o){if(!this.originalWidth||!this.originalHeight)return void window.setTimeout(function(){this.position(t,o)}.bind(this),100);var i=this.getWidthAndHeight(t,o),e=this.getLeft(i.width,o),n=this.getTop(i.height,o);this.el.style.width=i.width+"px",this.el.style.left=e+"px",this.el.style.top=n+"px",this.el.style.position="absolute"},MoodboardEl.prototype.getLeft=function(t,o){return Moodboard.randomNumber(0,o.width-t)},MoodboardEl.prototype.getTop=function(t,o){return Moodboard.randomNumber(0,o.height-t)},MoodboardEl.prototype.getWidthAndHeight=function(t,o){var i=o.width*o.height,e=t*i,n=e*o.variation;e=Moodboard.randomNumber(e-n,e+n);var r=this.originalWidth/this.originalHeight,s=Math.sqrt(e/r),a=e/s;return{width:a,height:s}};var Moodboard=function(t,o){o=o||{};var i=document.querySelectorAll(t);this.elements=i,this.coverage=o.coverage||.2,this.variation=o.variation||.2,this.resizeDelay=o.resizeDelay||300,this.disableResize=o.disableResize||!1,this.layoutElements=[],this.resizeTimer,this.initialize(),this.initLayout()};Moodboard.randomNumber=function(t,o){return Math.floor(Math.random()*o)+t},Moodboard.prototype.getViewportSize=function(){this.width=window.innerWidth,this.height=window.innerHeight},Moodboard.prototype.initialize=function(){this.polyfillBind(),this.polyfillForEach(),this.polyfillQuerySelectorAll(),this.addBodyJsClass(),this.checkElementsCount(),this.instantiateLayoutEls()},Moodboard.prototype.initLayout=function(){this.getViewportSize(),this.positionLayoutEls(),this.setUpResizeListener()},Moodboard.prototype.positionLayoutEls=function(){this.layoutElements.forEach(function(t){var o=this.coverage/this.elements.length;t.position(o,this)}.bind(this))},Moodboard.prototype.instantiateLayoutEls=function(){Array.prototype.forEach.call(this.elements,function(t){this.layoutElements.push(new MoodboardEl(t))}.bind(this))},Moodboard.prototype.checkElementsCount=function(){this.elements.length<1&&console.error("No elements given to the layout engine.")},Moodboard.prototype.setUpResizeListener=function(){this.disableResize||window.addEventListener("resize",function(){clearTimeout(this.resizeTimer),this.resizeTimer=setTimeout(function(){this.initLayout()}.bind(this),this.resizeDelay)}.bind(this))},Moodboard.prototype.addBodyJsClass=function(){var t=document.body,o="js";t.classList?t.classList.add(o):t.className+=" "+o},Moodboard.prototype.polyfillBind=function(){Function.prototype.bind||(Function.prototype.bind=function(t){var o=this;return function(){return o.apply(t,arguments)}})},Moodboard.prototype.polyfillForEach=function(){Array.prototype.forEach||(Array.prototype.forEach=function(t,o){var i,e=this,n=e.length,r=o?o:void 0;for(i=0;n>i;i+=1)e.hasOwnProperty(i)&&t.call(r,e[i],i,e);return void 0})},Moodboard.prototype.polyfillQuerySelectorAll=function(){document.querySelectorAll||(document.querySelectorAll=function(t){var o,i=document.createElement("style"),e=[];for(document.documentElement.firstChild.appendChild(i),document._qsa=[],i.styleSheet.cssText=t+"{x-qsa:expression(document._qsa && document._qsa.push(this))}",window.scrollBy(0,0),i.parentNode.removeChild(i);document._qsa.length;)o=document._qsa.shift(),o.style.removeAttribute("x-qsa"),e.push(o);return document._qsa=null,e})};