!function(){var a={}.hasOwnProperty,b=function(b,c){function d(){this.constructor=b}for(var e in c)a.call(c,e)&&(b[e]=c[e]);return d.prototype=c.prototype,b.prototype=new d,b.__super__=c.prototype,b},c=[].slice;!function(a){var d;if(null==a.imageIndexer)return a.imageIndexer=function(a){return d.getInstance(a)},a.imageIndexer.getClass=function(){return d},a.imageIndexer.version="0.1.5",d=function(){function d(){this._images={},this.withPreloading=!0}var e,f,g;return d._instances={},d.getInstance=function(a){return null==a&&(a="default"),a in this._instances?this._instances[a]:this._instances[a]=new d},d.cleanInstances=function(){return this._instances={}},d.InvalidArgsError=f=function(a){function c(a){this.message=a,this.name="InvalidArgsError",c.__super__.constructor.apply(this,arguments)}return b(c,a),c}(Error),d.NotFoundImageKeyError=g=function(a){function c(a){this.message=a,this.name="NotFoundImageKeyError",c.__super__.constructor.apply(this,arguments)}return b(c,a),c}(Error),d.DuplicatedImageKeyError=e=function(a){function c(a){this.message=a,this.name="DuplicatedImageKeyError",c.__super__.constructor.apply(this,arguments)}return b(c,a),c}(Error),d.prototype.clip=function(b,c,d,g,h,i){var j,k;if(null==i&&(i={}),j=a.extend({withPreloading:null},i),this._hasImageData(b))throw new e("The imageKey="+b+" already exists.");if(!this._withinSize(d,g,h))throw new f("Pos=["+g+"] size=["+h+"] is not within ["+d+"].");return(null!=(k=j.withPreloading)?k:this.withPreloading)&&this._preload(c),this._images[b]={type:"clip",url:c,realSize:d.slice(),clipPos:g.slice(),clipSize:h.slice()}},d.prototype.upload=function(a,b,c){return this.clip(a,b,c,[0,0],c.slice())},d.prototype.partition=function(b,c,d,g,h){var i,j,k,l;if(null==h&&(h={}),i=a.extend({targetPos:[0,0],targetSize:d.slice(),withPreloading:null},h),this._hasImageData(b))throw new e("The imageKey="+b+" already exists.");if(j=i.targetPos.slice(),k=i.targetSize.slice(),!this._withinSize(d,j,k))throw new f("Pos=["+j+"] size=["+k+"] is not within ["+d+"].");if(!this._isEqualDevidable(k,g))throw new f("Size=["+k+"] can't be divide equally by ["+g+"].");return(null!=(l=i.withPreloading)?l:this.withPreloading)&&this._preload(c),this._images[b]={type:"partition",url:c,realSize:d,partSize:g,targetPos:j,targetSize:k}},d.prototype._getImageData=function(a){var b,c;return null!=(b=null!=(c=this._images)?c[a]:void 0)?b:null},d.prototype._hasImageData=function(a){return null!==this._getImageData(a)},d.prototype._getImageDataOrError=function(a){var b;return function(){if(null!=(b=this._getImageData(a)))return b;throw new g("Not found image key="+a+".")}.call(this)},d.prototype._preload=function(a){return(new Image).src=a},d.prototype._withinSize=function(a,b,c){return a[0]>=b[1]+c[0]&&a[1]>=b[0]+c[1]},d.prototype._isEqualDevidable=function(a,b){return 0===a[0]%b[0]&&0===a[1]%b[1]},d.prototype._argsToPartIndex=function(a,b){var c;if(2===a.length)return[a[0],a[1]];if(1===a.length){if(a[0]instanceof Array)return[a[0][0],a[0][1]];if("number"==typeof a[0]&&a[0]>=1)return c=a[0]-1,[parseInt(c/b,10),c%b]}throw new f("["+a+"] is invalid part-index.")},d.prototype._partDataToPos=function(a,b,c){return null==c&&(c=[0,0]),[b[1]*a[0]+c[0],b[0]*a[1]+c[1]]},d.prototype.asChip=function(){var b,d,e,f,g;return e=arguments[0],b=2<=arguments.length?c.call(arguments,1):[],d=this._getImageDataOrError(e),"clip"===d.type?a("
").css({margin:0,padding:0,width:d.clipSize[0],height:d.clipSize[1],overflow:"hidden"}).append(a("").css({display:"block",position:"relative",margin:0,padding:0,top:-d.clipPos[0],left:-d.clipPos[1],width:d.realSize[0],height:d.realSize[1],border:"none"}).attr({src:d.url})):"partition"===d.type?(f=this._argsToPartIndex(b,d.targetSize[0]/d.partSize[0]),g=this._partDataToPos(f,d.partSize,d.targetPos),a("
").css({margin:0,padding:0,width:d.partSize[0],height:d.partSize[1],overflow:"hidden"}).append(a("").css({display:"block",position:"relative",margin:0,padding:0,top:-g[0],left:-g[1],width:d.realSize[0],height:d.realSize[1],border:"none"}).attr({src:d.url}))):void 0},d.prototype.asData=function(a){return this._getImageData(a)},d}()}(jQuery)}.call(this);