text: define(function(a){jQuery=a("jquery"),!function(a){"use strict";a.fn.imageScale=function(c){return this.each(function(){var h,i,j,k,d=this,e=a(this),f=e.data("imageScale"),g="IMG"===this.tagName?e:e.find("img");f?"string"==typeof c?f[c]():"object"==typeof c?(k=c.method||"scale",f[k](!1,c)):f.scale():(h=g[0].complete,i=a.extend({},a.fn.imageScale.defaults,"object"==typeof c&&c),j=function(){e.data("imageScale",f=new b(d,i)),f.scale(!0,i)},h?j.apply(e[0]):g.on("load",j).attr("src",g.attr("src")))})},a.fn.imageScale.defaults={scale:"best-fill",align:"center",parent:null,hideParentOverflow:!0,fadeInDuration:0,rescaleOnResize:!0,didScale:function(){},logLevel:0};var b=function(b,c){var e,f,g,h,d=this;d.options=c,d.element=b,e=d.$element=a(b),f=d.$img="IMG"===b.tagName?e:e.find("img"),g=d.img=f[0],d.src=f.attr("src"),d.imgWidth=g.naturalWidth||g.width,d.imgHeight=g.naturalHeight||g.height,h=d.$parent=c.parent?c.parent:a(e.parent()[0]),d.parent=h[0],"static"===h.css("position")&&h.css("position","relative"),c.rescaleOnResize&&a(window).resize(function(){d.scheduleScale()})};a.fn.imageScale.Constructor=b,b.prototype={NONE:"none",FILL:"fill",BEST_FILL:"best-fill",BEST_FIT:"best-fit",BEST_FIT_DOWN_ONLY:"best-fit-down",ALIGN_LEFT:"left",ALIGN_RIGHT:"right",ALIGN_CENTER:"center",ALIGN_TOP:"top",ALIGN_BOTTOM:"bottom",ALIGN_TOP_LEFT:"top-left",ALIGN_TOP_RIGHT:"top-right",ALIGN_BOTTOM_LEFT:"bottom-left",ALIGN_BOTTOM_RIGHT:"bottom-right",constructor:b,element:null,options:null,scale:function(a,b){var c,d,e,f,g,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x;if(!this._isDestroyed&&this._canScale!==!1){if(c=this,d=this.options,e=this.$parent,f=this.element,g=this.$element,this.img,i=this.$img,a)d.hideParentOverflow&&e.css({overflow:"hidden"});else if(this.src!==i.attr("src"))return this.destroy(),g.data("imageScale",null),g.imageScale(d),void 0;if(this._didScheduleScale=!1,!d.rescaleOnResize||b||this._needUpdate(this.parent)){if(b=b?b:{},j=b.transition,j&&(this._canScale=!1,g.css("transition","all "+j+"ms"),setTimeout(function(){c._canScale=null,g.css("transition","null")},j)),k=b.destWidth?b.destWidth:e.outerWidth(),l=b.destHeight?b.destHeight:e.outerHeight(),m=b.destWidth?b.destWidth:e.innerWidth(),n=b.destHeight?b.destHeight:e.innerHeight(),o=k-m,p=l-n,q=g.attr("data-scale"),r=g.attr("data-align"),s=q?q:d.scale,t=r?r:d.align,u=d.fadeInDuration,!s)return d.logLevel>2&&console.log("imageScale - DEBUG NOTICE: The scale property is null.",f),void 0;if(this._cacheDestWidth===k&&this._cacheDestHeight===l&&d.logLevel>2&&console.log("imageScale - DEBUG NOTICE: The parent size hasn't changed: dest width: '"+k+"' - dest height: '"+l+"'.",f),v=this.imgWidth,w=this.imgHeight,!(k&&l&&v&&w))return d.logLevel>0&&console.error("imageScale - DEBUG ERROR: The dimensions are incorrect: source width: '"+v+"' - source height: '"+w+"' - dest width: '"+k+"' - dest height: '"+l+"'.",f),void 0;this._cacheDestWidth=k,this._cacheDestHeight=l,x=this._innerFrameForSize(s,t,v,w,k,l),o&&(x.x-=o/2),p&&(x.y-=p/2),g.css({position:"absolute",top:x.y+"px",left:x.x+"px",width:x.width+"px",height:x.height+"px","max-width":"none"}),a&&u&&g.stop().animate({opacity:1},u),d.didScale.call(this,a,b)}}},destroy:function(){this._isDestroyed=!0,this.$element.removeData("imageScale")},_innerFrameForSize:function(a,b,c,d,e,f){var g,h,i;if(i={x:0,y:0,width:e,height:f},a===this.FILL)return i;switch(g=e/c,h=f/d,a){case this.BEST_FIT_DOWN_ONLY:a!==this.BEST_FIT_DOWN_ONLY&&this.options.logLevel>1&&console.warn("imageScale - DEBUG WARNING: The scale '"+a+"' was not understood."),a=c>e||d>f?h>g?g:h:1;break;case this.BEST_FIT:a=h>g?g:h;break;case this.NONE:a=1;break;default:a=g>h?g:h}switch(c*=a,d*=a,i.width=Math.round(c),i.height=Math.round(d),b){case this.ALIGN_LEFT:i.x=0,i.y=f/2-d/2;break;case this.ALIGN_RIGHT:i.x=e-c,i.y=f/2-d/2;break;case this.ALIGN_TOP:i.x=e/2-c/2,i.y=0;break;case this.ALIGN_BOTTOM:i.x=e/2-c/2,i.y=f-d;break;case this.ALIGN_TOP_LEFT:i.x=0,i.y=0;break;case this.ALIGN_TOP_RIGHT:i.x=e-c,i.y=0;break;case this.ALIGN_BOTTOM_LEFT:i.x=0,i.y=f-d;break;case this.ALIGN_BOTTOM_RIGHT:i.x=e-c,i.y=f-d;break;default:b!==this.ALIGN_CENTER&&this.options.logLevel>1&&console.warn("imageScale - DEBUG WARNING: The align '"+b+"' was not understood."),i.x=e/2-c/2,i.y=f/2-d/2}return i},_needUpdate:function(a){var b=a.clientHeight+" "+a.clientWidth;return this._lastParentSize!==b?(this._lastParentSize=b,!0):!1},scheduleScale:function(){if(!this._didScheduleScale)if(window.requestAnimationFrame){var a=this;this._didScheduleScale=!0,requestAnimationFrame(function(){setTimeout(function(){a.scale()},0)})}else this.scale()}}}(window.jQuery)});