(function(){"use strict";function t(){}function r(n,t){for(var i=n.length;i--;)if(n[i].listener===t)return i;return-1}function i(n){return function(){return this[n].apply(this,arguments)}}var n=t.prototype,u=this,f=u.EventEmitter;n.getListeners=function(n){var r,t,i=this._getEvents();if("object"==typeof n){r={};for(t in i)i.hasOwnProperty(t)&&n.test(t)&&(r[t]=i[t])}else r=i[n]||(i[n]=[]);return r};n.flattenListeners=function(n){for(var i=[],t=0;t<n.length;t+=1)i.push(n[t].listener);return i};n.getListenersAsObject=function(n){var t,i=this.getListeners(n);return i instanceof Array&&(t={},t[n]=i),t||i};n.addListener=function(n,t){var i,u=this.getListenersAsObject(n),f="object"==typeof t;for(i in u)u.hasOwnProperty(i)&&-1===r(u[i],t)&&u[i].push(f?t:{listener:t,once:!1});return this};n.on=i("addListener");n.addOnceListener=function(n,t){return this.addListener(n,{listener:t,once:!0})};n.once=i("addOnceListener");n.defineEvent=function(n){return this.getListeners(n),this};n.defineEvents=function(n){for(var t=0;t<n.length;t+=1)this.defineEvent(n[t]);return this};n.removeListener=function(n,t){var f,i,u=this.getListenersAsObject(n);for(i in u)u.hasOwnProperty(i)&&(f=r(u[i],t),-1!==f&&u[i].splice(f,1));return this};n.off=i("removeListener");n.addListeners=function(n,t){return this.manipulateListeners(!1,n,t)};n.removeListeners=function(n,t){return this.manipulateListeners(!0,n,t)};n.manipulateListeners=function(n,t,i){var r,u,f=n?this.removeListener:this.addListener,e=n?this.removeListeners:this.addListeners;if("object"!=typeof t||t instanceof RegExp)for(r=i.length;r--;)f.call(this,t,i[r]);else for(r in t)t.hasOwnProperty(r)&&(u=t[r])&&("function"==typeof u?f.call(this,r,u):e.call(this,r,u));return this};n.removeEvent=function(n){var t,r=typeof n,i=this._getEvents();if("string"===r)delete i[n];else if("object"===r)for(t in i)i.hasOwnProperty(t)&&n.test(t)&&delete i[t];else delete this._events;return this};n.removeAllListeners=i("removeEvent");n.emitEvent=function(n,t){var i,f,r,e,u=this.getListenersAsObject(n);for(r in u)if(u.hasOwnProperty(r))for(f=u[r].length;f--;)i=u[r][f],i.once===!0&&this.removeListener(n,i.listener),e=i.listener.apply(this,t||[]),e===this._getOnceReturnValue()&&this.removeListener(n,i.listener);return this};n.trigger=i("emitEvent");n.emit=function(n){var t=Array.prototype.slice.call(arguments,1);return this.emitEvent(n,t)};n.setOnceReturnValue=function(n){return this._onceReturnValue=n,this};n._getOnceReturnValue=function(){return this.hasOwnProperty("_onceReturnValue")?this._onceReturnValue:!0};n._getEvents=function(){return this._events||(this._events={})};t.noConflict=function(){return u.EventEmitter=f,t};"function"==typeof define&&define.amd?define("eventEmitter/EventEmitter",[],function(){return t}):"object"==typeof module&&module.exports?module.exports=t:this.EventEmitter=t}).call(this),function(n){function f(t){var i=n.event;return i.target=i.target||i.srcElement||t,i}var t=document.documentElement,r=function(){},i,u;t.addEventListener?r=function(n,t,i){n.addEventListener(t,i,!1)}:t.attachEvent&&(r=function(n,t,i){n[t+i]=i.handleEvent?function(){var t=f(n);i.handleEvent.call(i,t)}:function(){var t=f(n);i.call(n,t)};n.attachEvent("on"+t,n[t+i])});i=function(){};t.removeEventListener?i=function(n,t,i){n.removeEventListener(t,i,!1)}:t.detachEvent&&(i=function(n,t,i){n.detachEvent("on"+t,n[t+i]);try{delete n[t+i]}catch(r){n[t+i]=void 0}});u={bind:r,unbind:i};"function"==typeof define&&define.amd?define("eventie/eventie",u):n.eventie=u}(this),function(n,t){"use strict";"function"==typeof define&&define.amd?define(["eventEmitter/EventEmitter","eventie/eventie"],function(i,r){return t(n,i,r)}):"object"==typeof module&&module.exports?module.exports=t(n,require("wolfy87-eventemitter"),require("eventie")):n.imagesLoaded=t(n,n.EventEmitter,n.eventie)}(window,function(n,t,i){function o(n,t){for(var i in t)n[i]=t[i];return n}function l(n){return"[object Array]"==v.call(n)}function a(n){var t=[],i;if(l(n))t=n;else if("number"==typeof n.length)for(i=0;i<n.length;i++)t.push(n[i]);else t.push(n);return t}function r(n,t,i){if(!(this instanceof r))return new r(n,t,i);"string"==typeof n&&(n=document.querySelectorAll(n));this.elements=a(n);this.options=o({},this.options);"function"==typeof t?i=t:o(this.options,t);i&&this.on("always",i);this.getImages();e&&(this.jqDeferred=new e.Deferred);var u=this;setTimeout(function(){u.check()})}function u(n){this.img=n}function f(n,t){this.url=n;this.element=t;this.img=new Image}var e=n.jQuery,s=n.console,v=Object.prototype.toString,h,c;return r.prototype=new t,r.prototype.options={},r.prototype.getImages=function(){var n,t;for(this.images=[],n=0;n<this.elements.length;n++)t=this.elements[n],this.addElementImages(t)},r.prototype.addElementImages=function(n){var i,r,t,f,u,e;if("IMG"==n.nodeName&&this.addImage(n),this.options.background===!0&&this.addElementBackgroundImages(n),i=n.nodeType,i&&h[i]){for(r=n.querySelectorAll("img"),t=0;t<r.length;t++)f=r[t],this.addImage(f);if("string"==typeof this.options.background)for(u=n.querySelectorAll(this.options.background),t=0;t<u.length;t++)e=u[t],this.addElementBackgroundImages(e)}},h={1:!0,9:!0,11:!0},r.prototype.addElementBackgroundImages=function(n){for(var i,r=c(n),u=/url\(['"]*([^'"\)]+)['"]*\)/gi,t=u.exec(r.backgroundImage);null!==t;)i=t&&t[1],i&&this.addBackground(i,n),t=u.exec(r.backgroundImage)},c=n.getComputedStyle||function(n){return n.currentStyle},r.prototype.addImage=function(n){var t=new u(n);this.images.push(t)},r.prototype.addBackground=function(n,t){var i=new f(n,t);this.images.push(i)},r.prototype.check=function(){function i(n,t,i){setTimeout(function(){r.progress(n,t,i)})}var r=this,n,t;if(this.progressedCount=0,this.hasAnyBroken=!1,!this.images.length)return void this.complete();for(n=0;n<this.images.length;n++)t=this.images[n],t.once("progress",i),t.check()},r.prototype.progress=function(n,t,i){this.progressedCount++;this.hasAnyBroken=this.hasAnyBroken||!n.isLoaded;this.emit("progress",this,n,t);this.jqDeferred&&this.jqDeferred.notify&&this.jqDeferred.notify(this,n);this.progressedCount==this.images.length&&this.complete();this.options.debug&&s&&s.log("progress: "+i,n,t)},r.prototype.complete=function(){var t=this.hasAnyBroken?"fail":"done",n;(this.isComplete=!0,this.emit(t,this),this.emit("always",this),this.jqDeferred)&&(n=this.hasAnyBroken?"reject":"resolve",this.jqDeferred[n](this))},u.prototype=new t,u.prototype.check=function(){var n=this.getIsImageComplete();return n?void this.confirm(0!==this.img.naturalWidth,"naturalWidth"):(this.proxyImage=new Image,i.bind(this.proxyImage,"load",this),i.bind(this.proxyImage,"error",this),i.bind(this.img,"load",this),i.bind(this.img,"error",this),void(this.proxyImage.src=this.img.src))},u.prototype.getIsImageComplete=function(){return this.img.complete&&void 0!==this.img.naturalWidth},u.prototype.confirm=function(n,t){this.isLoaded=n;this.emit("progress",this,this.img,t)},u.prototype.handleEvent=function(n){var t="on"+n.type;this[t]&&this[t](n)},u.prototype.onload=function(){this.confirm(!0,"onload");this.unbindEvents()},u.prototype.onerror=function(){this.confirm(!1,"onerror");this.unbindEvents()},u.prototype.unbindEvents=function(){i.unbind(this.proxyImage,"load",this);i.unbind(this.proxyImage,"error",this);i.unbind(this.img,"load",this);i.unbind(this.img,"error",this)},f.prototype=new u,f.prototype.check=function(){i.bind(this.img,"load",this);i.bind(this.img,"error",this);this.img.src=this.url;var n=this.getIsImageComplete();n&&(this.confirm(0!==this.img.naturalWidth,"naturalWidth"),this.unbindEvents())},f.prototype.unbindEvents=function(){i.unbind(this.img,"load",this);i.unbind(this.img,"error",this)},f.prototype.confirm=function(n,t){this.isLoaded=n;this.emit("progress",this,this.element,t)},r.makeJQueryPlugin=function(t){t=t||n.jQuery;t&&(e=t,e.fn.imagesLoaded=function(n,t){var i=new r(this,n,t);return i.jqDeferred.promise(e(this))})},r.makeJQueryPlugin(),r})