/*
 COPYRIGHT 2009 ESRI

 TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
 Unpublished material - all rights reserved under the
 Copyright Laws of the United States and applicable international
 laws, treaties, and conventions.

 For additional information, contact:
 Environmental Systems Research Institute, Inc.
 Attn: Contracts and Legal Services Department
 380 New York Street
 Redlands, California, 92373
 USA

 email: contracts@esri.com
 */

if(!dojo._hasResource["esri.layers.agsimageservice"]){dojo._hasResource["esri.layers.agsimageservice"]=true;dojo.provide("esri.layers.agsimageservice");dojo.require("esri.layers.dynamic");dojo.require("esri.layers.agscommon");dojo.require("esri.utils");dojo.declare("esri.layers.ArcGISImageServiceLayer",esri.layers.DynamicMapServiceLayer,{constructor:function(_1,_2){this._url=esri.urlToObject(_1);var _3=_2&&_2.imageServiceParameters;this.format=_3&&_3.format;this.interpolation=_3?_3.interpolation:null;this.compressionQuality=_3?_3.compressionQuality:null;this.bandIds=_3?_3.bandIds:null;this.mosaicRule=_3?_3.mosaicRule:null;this.renderingRule=_3?_3.renderingRule:null;this._params=dojo.mixin({},this._url.query,{f:"image",interpolation:this.interpolation,format:this.format,compressionQuality:this.compressionQuality,bandIds:this.bandIds?this.bandIds.join(","):null},_3?_3.toJson():{});this._initLayer=dojo.hitch(this,this._initLayer);this.useMapImage=(_2&&_2.useMapImage)||false;this._loadCallback=_2&&_2.loadCallback;var _4=_2&&_2.resourceInfo;if(_4){this._initLayer(_4);}else{esri.request({url:this._url.path,content:dojo.mixin({f:"json"},this._url.query),callbackParamName:"callback",load:this._initLayer,error:this._errorHandler});}},disableClientCaching:false,_initLayer:function(_5,io){this._findCredential();dojo.mixin(this,_5);this.initialExtent=(this.fullExtent=this.extent=(new esri.geometry.Extent(_5.extent)));this.spatialReference=this.initialExtent.spatialReference;this.pixelSizeX=parseFloat(this.pixelSizeX);this.pixelSizeY=parseFloat(this.pixelSizeY);var i,il,_6=this.minValues,_7=this.maxValues,_8=this.meanValues,_9=this.stdvValues,bs=(this.bands=[]);for(i=0,il=this.bandCount;i<il;i++){bs[i]={min:_6[i],max:_7[i],mean:_8[i],stddev:_9[i]};}var _a=this.timeInfo;this.timeInfo=(_a&&_a.timeExtent)?new esri.layers.TimeInfo(_a):null;var _b=this.fields=[];var _c=_5.fields;if(_c){for(i=0;i<_c.length;i++){_b.push(new esri.layers.Field(_c[i]));}}this.version=_5.currentVersion;if(!this.version){var _d;if("fields" in _5||"objectIdField" in _5||"timeInfo" in _5){_d=10;}else{_d=9.3;}this.version=_d;}this.loaded=true;this.onLoad(this);var _e=this._loadCallback;if(_e){delete this._loadCallback;_e(this);}},getImageUrl:function(_f,_10,_11,_12){var sr=_f.spatialReference.wkid||dojo.toJson(_f.spatialReference.toJson());delete this._params._ts;var _13=this._url.path+"/exportImage?";dojo.mixin(this._params,{bbox:_f.xmin+","+_f.ymin+","+_f.xmax+","+_f.ymax,imageSR:sr,bboxSR:sr,size:_10+","+_11},this.disableClientCaching?{_ts:new Date().getTime()}:{});var _14=(this._params.token=this._getToken()),_15=esri._getProxiedUrl(_13+dojo.objectToQuery(dojo.mixin(this._params,{f:"image"})));if((_15.length>esri.config.defaults.io.postLength)||this.useMapImage){this._jsonRequest=esri.request({url:_13,content:dojo.mixin(this._params,{f:"json"}),callbackParamName:"callback",load:function(_16,io){var _17=_16.href;if(_14){_17+=(_17.indexOf("?")===-1?("?token="+_14):("&token="+_14));}_12(esri._getProxiedUrl(_17));},error:this._errorHandler});}else{_12(_15);}},setInterpolation:function(_18,_19){this.interpolation=(this._params.interpolation=_18);if(!_19){this.refresh(true);}},setCompressionQuality:function(_1a,_1b){this.compressionQuality=(this._params.compressionQuality=_1a);if(!_1b){this.refresh(true);}},setBandIds:function(ids,_1c){this.bandIds=ids;this._params.bandIds=ids.join(",");if(!_1c){this.refresh(true);}},setDefaultBandIds:function(_1d){this.bandIds=(this._params.bandIds=null);if(!_1d){this.refresh(true);}},setDisableClientCaching:function(_1e){this.disableClientCaching=_1e;},setMosaicRule:function(_1f,_20){this.mosaicRule=_1f;this._params.mosaicRule=dojo.toJson(_1f.toJson());if(!_20){this.refresh(true);}},setRenderingRule:function(_21,_22){this.renderingRule=_21;this._params.renderingRule=dojo.toJson(_21.toJson());if(!_22){this.refresh(true);}},setImageFormat:function(_23,_24){this.format=(this._params.format=_23);if(!_24){this.refresh(true);}},refresh:function(_25){if(_25){this.inherited(arguments);}else{var dc=this.disableClientCaching;this.disableClientCaching=true;this.inherited(arguments);this.disableClientCaching=dc;}},exportMapImage:function(_26,_27){var m=esri.config.defaults.map,p=dojo.mixin({size:m.width+","+m.height},this._params,_26?_26.toJson(this.normalization):{},{f:"json"});delete p._ts;this._exportMapImage(this._url.path+"/exportImage",p,_27);}});dojo.declare("esri.layers.ImageServiceParameters",null,{extent:null,width:null,height:null,imageSpatialReference:null,format:null,interpolation:null,compressionQuality:null,bandIds:null,timeExtent:null,mosaicRule:null,renderingRule:null,noData:null,toJson:function(_28){var ext=this.bbox||this.extent;ext=ext&&_28&&ext._normalize(true);var _29=ext?(ext.spatialReference.wkid||dojo.toJson(ext.spatialReference.toJson())):null,_2a=this.imageSpatialReference,_2b={bbox:ext?(ext.xmin+","+ext.ymin+","+ext.xmax+","+ext.ymax):null,bboxSR:_29,size:(this.width!==null&&this.height!==null?this.width+","+this.height:null),imageSR:(_2a?(_2a.wkid||dojo.toJson(_2a.toJson())):_29),format:this.format,interpolation:this.interpolation,compressionQuality:this.compressionQuality,bandIds:this.bandIds?this.bandIds.join(","):null,mosaicRule:this.mosaicRule?dojo.toJson(this.mosaicRule.toJson()):null,renderingRule:this.renderingRule?dojo.toJson(this.renderingRule.toJson()):null,noData:this.noData};var _2c=this.timeExtent;_2b.time=_2c?_2c.toJson().join(","):null;return esri.filter(_2b,function(_2d){if(_2d!==null){return true;}});}});dojo.mixin(esri.layers.ImageServiceParameters,{INTERPOLATION_BILINEAR:"RSP_BilinearInterpolation",INTERPOLATION_CUBICCONVOLUTION:"RSP_CubicConvolution",INTERPOLATION_MAJORITY:"RSP_Majority",INTERPOLATION_NEARESTNEIGHBOR:"RSP_NearestNeighbor"});dojo.declare("esri.layers.MosaicRule",null,{method:null,where:null,sortField:null,sortValue:null,ascending:false,lockRasterIds:null,viewpoint:null,objectIds:null,operation:null,toJson:function(){var _2e={mosaicMethod:this.method,where:this.where,sortField:this.sortField,sortValue:this.sortValue?dojo.toJson(this.sortValue):null,ascending:this.ascending,lockRasterIds:this.lockRasterIds,viewpoint:this.viewpoint?this.viewpoint.toJson():null,fids:this.objectIds,mosaicOperation:this.operation};return esri.filter(_2e,function(_2f){if(_2f!==null){return true;}});}});dojo.mixin(esri.layers.MosaicRule,{METHOD_NONE:"esriMosaicNone",METHOD_CENTER:"esriMosaicCenter",METHOD_NADIR:"esriMosaicNadir",METHOD_VIEWPOINT:"esriMosaicViewpoint",METHOD_ATTRIBUTE:"esriMosaicAttribute",METHOD_LOCKRASTER:"esriMosaicLockRaster",METHOD_NORTHWEST:"esriMosaicNorthwest",METHOD_SEAMLINE:"esriMosaicSeamline",OPERATION_FIRST:"MT_FIRST",OPERATION_LAST:"MT_LAST",OPERATION_MIN:"MT_MIN",OPERATION_MAX:"MT_MAX",OPERATION_MEAN:"MT_MEAN",OPERATION_BLEND:"MT_BLEND"});dojo.declare("esri.layers.RasterFunction",null,{functionName:null,"arguments":null,variableName:null,toJson:function(){var _30={rasterFunction:this.functionName,rasterFunctionArguments:this["arguments"],variableName:this.variableName};return esri.filter(_30,function(_31){if(_31!==null){return true;}});}});}