/*
 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.dijit.OverviewMap"]){dojo._hasResource["esri.dijit.OverviewMap"]=true;dojo.provide("esri.dijit.OverviewMap");dojo.require("dijit._Widget");dojo.require("dijit._Templated");dojo.require("dojo.dnd.Mover");dojo.require("dojo.dnd.Moveable");dojo.require("dojo.dnd.move");(function(){var _1=[dojo.moduleUrl("esri.dijit","css/OverviewMap.css")];var _2=document.getElementsByTagName("head").item(0),_3,i,il=_1.length;for(i=0;i<il;i++){_3=document.createElement("link");_3.type="text/css";_3.rel="stylesheet";_3.href=_1[i].toString();_2.appendChild(_3);}}());dojo.declare("esri.dijit.OverviewMap",[dijit._Widget,dijit._Templated],{widgetsInTemplate:true,templateString:"<div class=\"esriOverviewMap\">\r\n  <div class=\"ovwContainer\" dojoattachpoint=\"_body\" style=\"width: ${width}px; height: ${height}px;\">\r\n    <div id=\"${id}-map\" style=\"width: 100%; height: 100%;\">\r\n      <div class=\"ovwHighlight\" dojoattachpoint=\"_focusDiv\" title=\"${NLS_drag}\" style=\"border: 1px solid ${color}; background-color: ${color};\"></div>\r\n    </div>\r\n  </div>\r\n  <div class=\"ovwButton ovwController\" title=\"${NLS_show}\" dojoattachpoint=\"_controllerDiv\" dojoattachevent=\"onclick: _visibilityHandler\">\r\n  </div>\r\n  <div class=\"ovwButton ovwMaximizer\" title=\"${NLS_maximize}\" dojoattachpoint=\"_maximizerDiv\" dojoattachevent=\"onclick: _maximizeHandler\">\r\n  </div>\r\n</div>\r\n",basePath:dojo.moduleUrl("esri.dijit"),constructor:function(_4,_5){dojo.mixin(this,esri.bundle.widgets.overviewMap);_4=_4||{};if(!_4.map){console.error("esri.dijit.OverviewMap: "+this.NLS_noMap);return;}var _6={};if(_5){this._detached=true;_6=dojo.coords(_5,true);}this.map=_4.map;this.baseLayer=_4.baseLayer;this.width=_4.width||_6.w||this.map.width/4;this.height=_4.height||_6.h||this.map.height/4;this.attachTo=_4.attachTo||"top-right";this.expandFactor=_4.expandFactor||2;this.color=_4.color||"#000000";this.opacity=_4.opacity||0.5;this.maximizeButton=!!_4.maximizeButton;this.visible=!!_4.visible;this._mainMapLayer=this.map.getLayer(this.map.layerIds[0]);if(!this._mainMapLayer){console.error("esri.dijit.OverviewMap: "+this.NLS_noLayer);return;}var _7=this.baseLayer||this._mainMapLayer;var _8=this.map.spatialReference,_9=_7.spatialReference;if((_9.wkid!==_8.wkid)&&(_9.wkt!==_8.wkt)){console.error("esri.dijit.OverviewMap: "+this.NLS_invalidSR);return;}var _a=_7.declaredClass;if(_7 instanceof esri.layers.TiledMapServiceLayer){if(_4.baseLayer){this.baseLayer=_4.baseLayer;}else{if(_a.indexOf("VETiledLayer")!==-1){this.baseLayer=new esri.virtualearth.VETiledLayer({resourceInfo:_7.getResourceInfo(),culture:_7.culture,mapStyle:_7.mapStyle,bingMapsKey:_7.bingMapsKey});}else{if(_a.indexOf("OpenStreetMapLayer")!==-1){this.baseLayer=new esri.layers.OpenStreetMapLayer({tileServers:_7.tileServers});}else{this.baseLayer=new esri.layers.ArcGISTiledMapServiceLayer(_7.url,{resourceInfo:_7.getResourceInfo()});}}}}else{if(_7 instanceof esri.layers.DynamicMapServiceLayer){if(_4.baseLayer){this.baseLayer=_4.baseLayer;}else{if(_a.indexOf("ArcGISImageServiceLayer")!==-1){this.baseLayer=new esri.layers.ArcGISImageServiceLayer(_7.url);}else{this.baseLayer=new esri.layers.ArcGISDynamicMapServiceLayer(_7.url);this.baseLayer.setImageFormat("png24");}}}else{console.error("esri.dijit.OverviewMap: "+this.NLS_invalidType);return;}}if(this._detached){this.visible=true;}this._maximized=false;},startup:function(){this.inherited(arguments);if(dojo.isIE){if(!this.domNode.parentElement){this.map.container.appendChild(this.domNode);}}else{if(!this.domNode.parentNode){this.map.container.appendChild(this.domNode);}}if(this._detached){dojo.style(this._body,"display","block");dojo.style(this._controllerDiv,"display","none");dojo.style(this._maximizerDiv,"display","none");if(this.baseLayer.loaded){this._initialize();}else{dojo.connect(this.baseLayer,"onLoad",this,this._initialize);}}else{if(this.attachTo.split("-")[0]==="bottom"){this.domNode.insertBefore(this._maximizerDiv,this._controllerDiv);}if(!this.maximizeButton){dojo.addClass(this._maximizerDiv,"ovwDisabledButton");}dojo.addClass(this.domNode,{"top-left":"ovwTL","top-right":"ovwTR","bottom-left":"ovwBL","bottom-right":"ovwBR"}[this.attachTo]);dojo.addClass(this._controllerDiv,"ovwShow");dojo.addClass(this._maximizerDiv,"ovwMaximize");if(this.visible){var _b=function(){this.visible=false;this._show();};if(this.baseLayer.loaded){_b.call(this);}else{dojo.connect(this.baseLayer,"onLoad",this,_b);}}}dojo.style(this._focusDiv,"opacity",this.opacity);},destroy:function(){this._deactivate();if(this.overviewMap){this.overviewMap.destroy();}this.overviewMap=this.baseLayer=null;this.inherited(arguments);},resize:function(_c){if(!_c||_c.w<=0||_c.h<=0){return;}this._resize(_c.w,_c.h);},_visibilityHandler:function(){if(this.visible){this._hide();}else{this._show();}},_show:function(){if(!this.visible){var _d=this._controllerDiv;_d.title=this.NLS_hide;dojo.removeClass(_d,"ovwShow");dojo.addClass(_d,"ovwHide");esri.show(this._body);esri.show(this._maximizerDiv);this._initialize();this.visible=true;}},_hide:function(){if(this.visible){var _e=this._controllerDiv;_e.title=this.NLS_show;dojo.removeClass(_e,"ovwHide");dojo.addClass(_e,"ovwShow");if(this._maximized){this._maximizeHandler();}esri.hide(this._body);esri.hide(this._maximizerDiv);this._deactivate();this.visible=false;}},_maximizeHandler:function(){var _f=this._maximizerDiv;if(this._maximized){_f.title=this.NLS_maximize;dojo.removeClass(_f,"ovwRestore");dojo.addClass(_f,"ovwMaximize");this._resize(this.width,this.height);}else{_f.title=this.NLS_restore;dojo.removeClass(_f,"ovwMaximize");dojo.addClass(_f,"ovwRestore");this._resize(this.map.width,this.map.height);}this._maximized=!this._maximized;},_resize:function(_10,_11){dojo.style(this._body,{width:_10+"px",height:_11+"px"});var _12=esri.config.defaults.map.panDuration,_13=this.overviewMap;esri.config.defaults.map.panDuration=0;_13.resize(true);_13.centerAt(this._focusExtent.getCenter());esri.config.defaults.map.panDuration=_12;},_initialize:function(){if(!this.overviewMap){var _14;_14=(this.overviewMap=new esri.Map(this.id+"-map",{slider:false,lods:this._overviewLods,wrapAround180:this.map.wrapAround180}));dojo.connect(_14,"onLoad",this,function(){this._map_resize_override=dojo.hitch(_14,this._map_resize_override);_14.disableMapNavigation();this._activate();});_14.addLayer(this.baseLayer);}else{this._activate();}},_activate:function(){var map=this.map,_15=this.overviewMap;this._moveableHandle=new dojo.dnd.Moveable(this._focusDiv);this._soeConnect=dojo.connect(map,"onExtentChange",this,this._syncOverviewMap);this._ufoConnect=dojo.connect(map,"onPan",this,this._updateFocus);this._oecConnect=dojo.connect(_15,"onExtentChange",this,this._ovwExtentChangeHandler);this._opaConnect=dojo.connect(_15,"onPan",this,this._ovwPanHandler);this._ozsConnect=dojo.connect(_15,"onZoomStart",this,function(){esri.hide(this._focusDiv);});this._ozeConnect=dojo.connect(_15,"onZoomEnd",this,function(){esri.show(this._focusDiv);});this._omsConnect=dojo.connect(this._moveableHandle,"onMoveStop",this,this._moveStopHandler);this._syncOverviewMap(map.extent,null,null,null);},_deactivate:function(){dojo.disconnect(this._soeConnect);dojo.disconnect(this._ufoConnect);dojo.disconnect(this._oecConnect);dojo.disconnect(this._opaConnect);dojo.disconnect(this._ozsConnect);dojo.disconnect(this._ozeConnect);dojo.disconnect(this._omsConnect);if(this._moveableHandle){this._moveableHandle.destroy();}},_syncOverviewMap:function(ext,_16,_17,lod){if(this._suspendPanHandling){this._suspendPanHandling=false;return;}this._focusExtent=ext;this.overviewMap.setExtent(ext.expand(this.expandFactor),true);},_updateFocus:function(ext){if(this._suspendPanHandling){return;}this._focusExtent=ext;this._drawFocusDiv(ext);},_drawFocusDiv:function(ext,_18){var _19=this.overviewMap;var tl=_19.toScreen(new esri.geometry.Point(ext.xmin,ext.ymax,_19.spatialReference));var br=_19.toScreen(new esri.geometry.Point(ext.xmax,ext.ymin,_19.spatialReference));var _1a=br.x-tl.x,_1b=br.y-tl.y,_1c=true;if((_1a>this.overviewMap.width)&&(_1b>this.overviewMap.height)){_1c=false;}dojo.style(this._focusDiv,{left:tl.x+(_18?_18.x:0)+"px",top:tl.y+(_18?_18.y:0)+"px",width:_1a+"px",height:_1b+"px",display:_1c?"block":"none"});},_moveStopHandler:function(evt){var _1d=this._moveableHandle.node.style;var ext=this._focusExtent;var _1e=this.overviewMap;var _1f=_1e.toMap(new esri.geometry.Point(parseInt(_1d.left,10),parseInt(_1d.top,10)));var _20=new esri.geometry.Point(ext.xmin,ext.ymax,_1e.spatialReference);this._focusExtent=ext.offset(_1f.x-_20.x,_1f.y-_20.y);if(this._maximized){this._maximizeHandler();}else{_1e.centerAt(this._focusExtent.getCenter());}this._suspendPanHandling=true;this.map.setExtent(this._focusExtent);},_ovwExtentChangeHandler:function(){this._drawFocusDiv(this._focusExtent);},_ovwPanHandler:function(ext,_21){this._drawFocusDiv(this._focusExtent,_21);}});}