/*
 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
 */
//>>built
define("esri/PopupBase",["dojo/_base/declare","dojo/_base/lang","dojo/_base/array","dojo/_base/Color","dojo/_base/Deferred","dojo/has","esri/kernel","esri/graphic","esri/geometry/Point","esri/geometry/jsonUtils","esri/geometry/mathUtils","esri/geometry/webMercatorUtils","esri/symbols/SimpleMarkerSymbol","esri/symbols/SimpleLineSymbol","esri/symbols/CartographicLineSymbol","esri/symbols/SimpleFillSymbol","esri/Evented"],function(_1,_2,_3,_4,_5,_6,_7,_8,_9,_a,_b,_c,_d,_e,_f,_10,_11){var _12=_1(_11,{declaredClass:"esri.PopupBase",_evtMap:{"set-features":true,"clear-features":true,"selection-change":true,"dfd-complete":true},onSetFeatures:function(){},onClearFeatures:function(){},onSelectionChange:function(){},onDfdComplete:function(){},initialize:function(){this.count=0;this.selectedIndex=-1;},cleanup:function(){this.features=this.deferreds=null;},setFeatures:function(arg){if(!arg||!arg.length){return;}this.clearFeatures();var _13,_14;if(arg[0] instanceof _5){_14=arg;}else{_13=arg;}if(_13){this._updateFeatures(null,_13);}else{this.deferreds=_14;_14=_14.slice(0);_3.forEach(_14,function(dfd){dfd.addBoth(_2.hitch(this,this._updateFeatures,dfd));},this);}},clearFeatures:function(){this.features=this.deferreds=this._marked=null;this.count=0;var _15=this.selectedIndex;this.selectedIndex=-1;if(_15>-1){this.onSelectionChange();}this.onClearFeatures();},getSelectedFeature:function(){var _16=this.features;if(_16){return _16[this.selectedIndex];}},select:function(_17){if(_17<0||_17>=this.count){return;}this.selectedIndex=_17;this.onSelectionChange();},enableHighlight:function(map){this._highlighted=map.graphics.add(new _8(new _9(0,0,map.spatialReference)));this._highlighted.hide();if(!this.markerSymbol){var _18=(this.markerSymbol=new _d());_18.setStyle(_d.STYLE_TARGET);_18._setDim(16,16,7);_18.setOutline(new _f(_e.STYLE_SOLID,new _4([0,255,255]),2,_f.CAP_ROUND,_f.JOIN_ROUND));_18.setColor(new _4([0,0,0,0]));}if(!this.lineSymbol){this.lineSymbol=new _e(_e.STYLE_SOLID,new _4([0,255,255]),2);}if(!this.fillSymbol){this.fillSymbol=new _10(_10.STYLE_NULL,new _e(_e.STYLE_SOLID,new _4([0,255,255]),2),new _4([0,0,0,0]));}},disableHighlight:function(map){var _19=this._highlighted;if(_19){_19.hide();map.graphics.remove(_19);delete this._highlighted;}this.markerSymbol=this.lineSymbol=this.fillSymbol=null;},showHighlight:function(){var _1a=this.features&&this.features[this.selectedIndex];if(this._highlighted&&_1a&&_1a.geometry){this._highlighted.show();}},hideHighlight:function(){if(this._highlighted){this._highlighted.hide();}},updateHighlight:function(map,_1b){var _1c=_1b.geometry,_1d=this._highlighted;if(!_1c||!_1d){if(_1d){_1d.hide();}return;}_1d.hide();if(!_1d.getLayer()&&map){map.graphics.add(_1d);}_1d.setGeometry(_a.fromJson(_1c.toJson()));var _1e;switch(_1c.type){case "point":case "multipoint":_1e=this.markerSymbol;_1e.setOffset(0,0);_1e.setAngle(0);var lyr=_1b.getLayer();if(lyr){var _1f=lyr._getSymbol(_1b),_20,_21,_22=0,_23=0,_24=0;if(_1f){switch(_1f.type){case "simplemarkersymbol":_20=_21=(_1f.size||0);break;case "picturemarkersymbol":_20=(_1f.width||0);_21=(_1f.height||0);break;}_22=_1f.xoffset||0;_23=_1f.yoffset||0;_24=_1f.angle||0;}if(_20&&_21){_1e._setDim(_20+1,_21+1,7);}_1e.setOffset(_22,_23);_1e.setAngle(_24);}break;case "polyline":_1e=this.lineSymbol;break;case "polygon":_1e=this.fillSymbol;break;}_1d.setSymbol(_1e);},showClosestFirst:function(_25){var _26=this.features;if(_26&&_26.length){if(_26.length>1){var i,_27=Infinity,_28=-1,_29,_2a=_b.getLength,_2b,_2c=_25.spatialReference,_2d,_2e;_25=_25.normalize();for(i=_26.length-1;i>=0;i--){_29=_26[i].geometry;if(!_29){continue;}_2d=_29.spatialReference;_2b=0;try{_2e=(_29.type==="point")?_29:_29.getExtent().getCenter();_2e=_2e.normalize();if(_2c&&_2d&&!_2c.equals(_2d)&&_2c._canProject(_2d)){_2e=_2c.isWebMercator()?_c.geographicToWebMercator(_2e):_c.webMercatorToGeographic(_2e);}_2b=_2a(_25,_2e);}catch(e){}if(_2b>0&&_2b<_27){_27=_2b;_28=i;}}if(_28>0){_26.splice(0,0,_26.splice(_28,1)[0]);this.select(0);}}}else{if(this.deferreds){this._marked=_25;}}},_unbind:function(dfd){var _2f=_3.indexOf(this.deferreds,dfd);if(_2f===-1){return;}this.deferreds.splice(_2f,1);if(!this.deferreds.length){this.deferreds=null;return 2;}return 1;},_fireComplete:function(_30){var _31=this._marked;if(_31){this._marked=null;this.showClosestFirst(_31);}this.onDfdComplete(_30);},_updateFeatures:function(dfd,_32){if(dfd){if(this.deferreds){var res=this._unbind(dfd);if(!res){return;}if(_32&&_32 instanceof Error){this._fireComplete(_32);if(res===2){this.onSetFeatures();}return;}if(_32&&_32.length){if(!this.features){this.features=_32;this.count=_32.length;this.selectedIndex=0;this._fireComplete();if(res===2){this.onSetFeatures();}this.select(0);}else{var _33=_3.filter(_32,function(_34){return _3.indexOf(this.features,_34)===-1;},this);this.features=this.features.concat(_33);this.count=this.features.length;this._fireComplete();if(res===2){this.onSetFeatures();}}}else{this._fireComplete();if(res===2){this.onSetFeatures();}}}}else{this.features=_32;this.count=_32.length;this.selectedIndex=0;this.onSetFeatures();this.select(0);}}});if(_6("extend-esri")){_7.PopupBase=_12;}return _12;});