OpenLayers.Layer.Zoomify=OpenLayers.Class(OpenLayers.Layer.Grid,{url:null,size:null,isBaseLayer:!0,standardTileSize:256,tileOriginCorner:"tl",numberOfTiers:0,tileCountUpToTier:[],tierSizeInTiles:[],tierImageSize:[],initialize:function(e,t,i,n){this.initializeZoomify(i);var r=[];r.push(e,t,i,{},n),OpenLayers.Layer.Grid.prototype.initialize.apply(this,r)},initializeZoomify:function(e){var t=e.clone(),i=new OpenLayers.Size(Math.ceil(t.w/this.standardTileSize),Math.ceil(t.h/this.standardTileSize));for(this.tierSizeInTiles.push(i),this.tierImageSize.push(t);t.w>this.standardTileSize||t.h>this.standardTileSize;)t=new OpenLayers.Size(Math.floor(t.w/2),Math.floor(t.h/2)),i=new OpenLayers.Size(Math.ceil(t.w/this.standardTileSize),Math.ceil(t.h/this.standardTileSize)),this.tierSizeInTiles.push(i),this.tierImageSize.push(t);this.tierSizeInTiles.reverse(),this.tierImageSize.reverse(),this.numberOfTiers=this.tierSizeInTiles.length,this.tileCountUpToTier[0]=0;for(var n=1;this.numberOfTiers>n;n++)this.tileCountUpToTier.push(this.tierSizeInTiles[n-1].w*this.tierSizeInTiles[n-1].h+this.tileCountUpToTier[n-1])},destroy:function(){OpenLayers.Layer.Grid.prototype.destroy.apply(this,arguments),this.tileCountUpToTier.length=0,this.tierSizeInTiles.length=0,this.tierImageSize.length=0},clone:function(e){return null==e&&(e=new OpenLayers.Layer.Zoomify(this.name,this.url,this.size,this.options)),e=OpenLayers.Layer.Grid.prototype.clone.apply(this,[e])},getURL:function(e){e=this.adjustBounds(e);var t=this.map.getResolution(),i=Math.round((e.left-this.tileOrigin.lon)/(t*this.tileSize.w)),n=Math.round((this.tileOrigin.lat-e.top)/(t*this.tileSize.h)),r=this.map.getZoom(),o=i+n*this.tierSizeInTiles[r].w+this.tileCountUpToTier[r],s="TileGroup"+Math.floor(o/256)+"/"+r+"-"+i+"-"+n+".jpg",a=this.url;return OpenLayers.Util.isArray(a)&&(a=this.selectUrl(s,a)),a+s},getImageSize:function(){if(arguments.length>0){var e=this.adjustBounds(arguments[0]),t=this.map.getResolution(),i=Math.round((e.left-this.tileOrigin.lon)/(t*this.tileSize.w)),n=Math.round((this.tileOrigin.lat-e.top)/(t*this.tileSize.h)),r=this.map.getZoom(),o=this.standardTileSize,s=this.standardTileSize;if(i==this.tierSizeInTiles[r].w-1)var o=this.tierImageSize[r].w%this.standardTileSize;if(n==this.tierSizeInTiles[r].h-1)var s=this.tierImageSize[r].h%this.standardTileSize;return new OpenLayers.Size(o,s)}return this.tileSize},setMap:function(){OpenLayers.Layer.Grid.prototype.setMap.apply(this,arguments),this.tileOrigin=new OpenLayers.LonLat(this.map.maxExtent.left,this.map.maxExtent.top)},calculateGridLayout:function(e,t,i){var n=i*this.tileSize.w,r=i*this.tileSize.h,o=e.left-t.lon,s=Math.floor(o/n)-this.buffer,a=o/n-s,l=-a*this.tileSize.w,c=t.lon+s*n,u=t.lat-e.top+r,h=Math.floor(u/r)-this.buffer,d=h-u/r,p=d*this.tileSize.h,f=t.lat-r*h;return{tilelon:n,tilelat:r,tileoffsetlon:c,tileoffsetlat:f,tileoffsetx:l,tileoffsety:p}},CLASS_NAME:"OpenLayers.Layer.Zoomify"});