/*
 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
 */

window[esri._dojoScopeName||"dojo"]._xdResourceLoaded(function(_1,_2,_3){return {depends:[["provide","esri.layers.MapImageLayer"],["require","esri.utils"],["require","esri.layers.layer"],["require","esri.geometry"]],defineResource:function(_4,_5,_6){if(!_4._hasResource["esri.layers.MapImageLayer"]){_4._hasResource["esri.layers.MapImageLayer"]=true;_4.provide("esri.layers.MapImageLayer");_4.require("esri.utils");_4.require("esri.layers.layer");_4.require("esri.geometry");_4.declare("esri.layers.MapImageLayer",[esri.layers.Layer],{"-chains-":{constructor:"manual"},constructor:function(_7){this.inherited(arguments,[null,_7]);this._mapImages=[];var _8=_4.hitch;this._panStart=_8(this,this._panStart);this._pan=_8(this,this._pan);this._extentChange=_8(this,this._extentChange);this._zoom=_8(this,this._zoom);this._zoomStart=_8(this,this._zoomStart);this._scale=_8(this,this._scale);this._resize=_8(this,this._resize);this.loaded=true;this.onLoad(this);},opacity:1,_transform:esri._getDOMAccessor("transform"),addImage:function(_9){var _a=this._mapImages.push(_9);_a=_a-1;_9._idx=_a;_9._layer=this;if(this._div){this._createImage(_9,_a);}},removeImage:function(_b){if(_b){var _c=_b._idx,_d=this._mapImages;if(_d[_c]===_b){delete _d[_c];var _e=_b._node;if(_e){this._clearEvents(_e);_e.e_idx=_e.e_bl=_e.e_tr=_e.e_l=_e.e_t=_e.e_w=_e.e_h=null;if(_e.parentNode){_e.parentNode.removeChild(_e);_4.destroy(_e);}}_b._node=_b._idx=_b._layer=null;}}},removeAllImages:function(){var _f=this._mapImages,i,len=_f.length;for(i=0;i<len;i++){var _10=_f[i];if(_10){this.removeImage(_10);}}this._mapImages=[];},getImages:function(){var _11=this._mapImages,_12=[],i,len=_11.length;for(i=0;i<len;i++){if(_11[i]){_12.push(_11[i]);}}return _12;},setOpacity:function(_13){if(this.opacity!=_13){this.onOpacityChange(this.opacity=_13);}},onOpacityChange:function(_14){var div=this._div,i,len,_15;if(div){if(!_4.isIE||_4.isIE>8){_4.style(div,"opacity",_14);}else{_15=div.childNodes;len=_15.length;for(i=0;i<len;i++){_4.style(_15[i],"opacity",_14);}}}},_createImage:function(_16,idx){var _17=_4.create("img");_4.style(_17,{position:"absolute"});if(_4.isIE<=8){_4.style(_17,"opacity",this.opacity);}if(_16.rotation){var _18="rotate("+(360-_16.rotation)+"deg)";if(_4.isIE<9){}else{_4.style(_17,this._transform,_18);_4.style(_17,"transform",_18);}}_16._node=_17;_17.e_idx=idx;_17.e_layer=this;_17.e_load=_4.connect(_17,"onload",esri.layers.MapImageLayer.prototype._imageLoaded);_17.e_error=_4.connect(_17,"onerror",esri.layers.MapImageLayer.prototype._imageError);_17.e_abort=_4.connect(_17,"onabort",esri.layers.MapImageLayer.prototype._imageError);_17.src=_16.href;},_imageLoaded:function(evt,img){var _19=img||evt.target||evt.currentTarget,_1a=_19.e_layer,_1b=_1a._mapImages[_19.e_idx];if(_1a._map&&(_1a._map.__zooming||_1a._map.__panning)){_1a._standby.push(_19);return;}_1a._clearEvents(_19);if(!_1b||_1b._node!==_19){return;}if(_1a._map){_1a._attach(_1b);}},_imageError:function(evt){var _1c=evt.target||evt.currentTarget,_1d=_1c.e_layer,_1e=_1d._mapImages[_1c.e_idx];_1d._clearEvents(_1c);if(_1e){_1e._node=null;}},_clearEvents:function(_1f){var _20=_4.disconnect;_20(_1f.e_load);_20(_1f.e_error);_20(_1f.e_abort);_1f.e_load=_1f.e_error=_1f.e_abort=_1f.e_layer=null;},_attach:function(_21){var _22=_21.extent,_23,_24=_22.spatialReference,_25=this._sr,div=this._div,_26=_21._node,_27=new esri.geometry.Point({x:_22.xmin,y:_22.ymin}),_28=new esri.geometry.Point({x:_22.xmax,y:_22.ymax});if(_25.wkid){_23=(_25._isWebMercator()&&_24._isWebMercator())||(_25.wkid===_24.wkid);}else{if(_25.wkt){_23=(_25.wkt===_24.wkt);}}if(!_23){if(_25._isWebMercator()&&_24.wkid===4326){_27=esri.geometry.geographicToWebMercator(_27);_28=esri.geometry.geographicToWebMercator(_28);}else{if(_24._isWebMercator()&&_25.wkid===4326){_27=esri.geometry.webMercatorToGeographic(_27);_28=esri.geometry.webMercatorToGeographic(_28);}}}_26.e_bl=_27;_26.e_tr=_28;if(_21.visible){this._setPos(_26,div._left,div._top);(this._active||div).appendChild(_26);}},_setPos:function(_29,_2a,_2b){var _2c=_29.e_bl,_2d=_29.e_tr,map=this._map;_2c=map.toScreen(_2c);_2d=map.toScreen(_2d);var _2e=_2c.x-_2a,top=_2d.y-_2b,_2f=Math.abs(_2d.x-_2c.x),_30=Math.abs(_2c.y-_2d.y),css={width:_2f+"px",height:_30+"px"},_31=this._mapImages[_29.e_idx];if(map.navigationMode==="css-transforms"){css[esri._css.names.transform]=esri._css.translate(_2e,top)+(_31.rotation?(" "+esri._css.rotate(360-_31.rotation)):"");}else{css.left=_2e+"px";css.top=top+"px";}_4.style(_29,css);_29.e_l=_2e;_29.e_t=top;_29.e_w=_2f;_29.e_h=_30;},_setMap:function(map,_32){this._map=map;this._sr=map.spatialReference;var div=this._div=_4.create("div",null,_32),_33=esri._css.names,css={position:"absolute"},vd=map.__visibleDelta;if(!_4.isIE||_4.isIE>8){css.opacity=this.opacity;}if(map.navigationMode==="css-transforms"){css[_33.transform]=esri._css.translate(vd.x,vd.y);_4.style(div,css);div._left=vd.x;div._top=vd.y;css={position:"absolute",width:map.width+"px",height:map.height+"px",overflow:"visible"};this._active=_4.create("div",null,div);_4.style(this._active,css);this._passive=_4.create("div",null,div);_4.style(this._passive,css);}else{div._left=0;div._top=0;_4.style(div,css);}this._standby=[];var _34=this._mapImages,i,len=_34.length;for(i=0;i<len;i++){var _35=_34[i],_36=_35._node;if(!_36){this._createImage(_35,_35._idx);}}this.onVisibilityChange(this.visible);return div;},_unsetMap:function(map,_37){this._disconnect();var div=this._div;if(div){var _38=this._mapImages,i,len=_38.length;for(i=0;i<len;i++){var _39=_38[i];if(_39){var _3a=_39._node;if(_3a){this._clearEvents(_3a);_3a.e_idx=_3a.e_bl=_3a.e_tr=_3a.e_l=_3a.e_t=_3a.e_w=_3a.e_h=null;}_39._node=null;}}_37.removeChild(div);_4.destroy(div);}this._map=this._div=this._sr=this._active=this._passive=this._standby=null;},onVisibilityChange:function(_3b){var div=this._div;if(div){if(_3b){this._redraw();this._connect(this._map);esri.show(div);}else{this._disconnect();esri.hide(div);}}},_connect:function(map){if(!this._connections){var _3c=_4.connect,_3d=(map.navigationMode==="css-transforms");this._connections=[_3c(map,"onPanStart",this._panStart),_3c(map,"onPan",this._pan),_3c(map,"onExtentChange",this._extentChange),_3d&&_3c(map,"onZoomStart",this._zoomStart),_3d?_3c(map,"onScale",this._scale):_3c(map,"onZoom",this._zoom),_3d&&_3c(map,"onResize",this._resize)];}},_disconnect:function(){if(this._connections){_4.forEach(this._connections,_4.disconnect);this._connections=null;}},_panStart:function(){this._panL=this._div._left;this._panT=this._div._top;},_pan:function(_3e,_3f){var div=this._div;div._left=this._panL+_3f.x;div._top=this._panT+_3f.y;if(this._map.navigationMode==="css-transforms"){_4.style(div,esri._css.names.transform,esri._css.translate(div._left,div._top));}else{_4.style(div,{left:div._left+"px",top:div._top+"px"});}},_extentChange:function(_40,_41,_42){if(_42){this._redraw(this._map.navigationMode==="css-transforms");}else{if(_41){this._pan(_40,_41);}}var i,_43=this._standby;if(_43&&_43.length){for(i=_43.length-1;i>=0;i--){this._imageLoaded(null,_43[i]);_43.splice(i,1);}}},_redraw:function(_44){if(_44){var _45=this._passive,_46=esri._css.names;_4.style(_45,_46.transition,"none");this._moveImages(_45,this._active);_4.style(_45,_46.transform,"none");}var div=this._active||this._div,_47=this._div._left,_48=this._div._top,i,len=div.childNodes.length,_49;for(i=0;i<len;i++){_49=div.childNodes[i];this._setPos(_49,_47,_48);}},_zoom:function(_4a,_4b,_4c){var div=this._div,_4d=div._left,_4e=div._top,i,len=div.childNodes.length,_4f;for(i=0;i<len;i++){_4f=div.childNodes[i];var _50=_4f.e_w*_4b,_51=_4f.e_h*_4b,_52=(_4c.x-_4d-_4f.e_l)*(_50-_4f.e_w)/_4f.e_w,_53=(_4c.y-_4e-_4f.e_t)*(_51-_4f.e_h)/_4f.e_h;_52=isNaN(_52)?0:_52;_53=isNaN(_53)?0:_53;_4.style(_4f,{left:(_4f.e_l-_52)+"px",top:(_4f.e_t-_53)+"px",width:_50+"px",height:_51+"px"});}},_zoomStart:function(){this._moveImages(this._active,this._passive);},_moveImages:function(_54,_55){var _56=_54.childNodes,i,len=_56.length;if(len>0){for(i=len-1;i>=0;i--){_55.appendChild(_56[i]);}}},_scale:function(mtx,_57){var css={},_58=esri._css.names,_59=this._passive;_4.style(_59,_58.transition,_57?"none":(_58.transformName+" "+esri.config.defaults.map.zoomDuration+"ms ease"));css[_58.transform]=esri._css.matrix(mtx);_4.style(_59,_58.transform,esri._css.matrix(mtx));},_resize:function(_5a,_5b,_5c){_4.style(this._active,{width:_5b+"px",height:_5c+"px"});_4.style(this._passive,{width:_5b+"px",height:_5c+"px"});}});_4.extend(esri.layers.MapImage,{visible:true,getLayer:function(){return this._layer;},getNode:function(){return this._node;},show:function(){if(!this.visible){this.visible=true;var _5d=this._node,_5e=this._layer,div;if(_5d){div=_5e&&_5e._div;if(div){_5e._setPos(_5d,div._left,div._top);(_5e._active||div).appendChild(_5d);}esri.show(_5d);}}},hide:function(){if(this.visible){this.visible=false;var _5f=this._node;if(_5f){esri.hide(_5f);if(_5f.parentNode){_5f.parentNode.removeChild(_5f);}}}}});}}};});