/*
 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.dijit.Bookmarks"],["require","esri.map"],["require","esri.geometry"]],defineResource:function(_4,_5,_6){if(!_4._hasResource["esri.dijit.Bookmarks"]){_4._hasResource["esri.dijit.Bookmarks"]=true;_4.provide("esri.dijit.Bookmarks");_4.require("esri.map");_4.require("esri.geometry");_4.declare("esri.dijit.BookmarkItem",null,{constructor:function(_7){this.name=_7.name;this.extent=_7.extent;},toJson:function(){var _8={};var _9=this.extent.toJson();_8.extent={spatialReference:_9.spatialReference,xmax:_9.xmax,xmin:_9.xmin,ymax:_9.ymax,ymin:_9.ymin};_8.name=this.name;return _8;}});_4.declare("esri.dijit.Bookmarks",null,{constructor:function(_a,_b){this.map=_a.map;this.editable=_a.editable;this.initBookmarks=_a.bookmarks;this._clickHandlers=this._mouseOverHandlers=this._mouseOutHandlers=this._removeHandlers=this._editHandlers=[];this.bookmarkDomNode=_4.create("div");_4.addClass(this.bookmarkDomNode,"esriBookmarks");this.bookmarkTable=_4.create("table");_4.addClass(this.bookmarkTable,"esriBookmarkTable");this.bookmarkDomNode.appendChild(this.bookmarkTable);_b=_4.byId(_b);_b.appendChild(this.bookmarkDomNode);this._addInitialBookmarks();},onClick:function(){},onEdit:function(){},onRemove:function(){},addBookmark:function(_c){var _d;if(_c.declaredClass=="esri.dijit.BookmarkItem"){_d=_c;this.bookmarks.push(_d);}else{var _e=new esri.geometry.Extent(_c.extent);_d=new esri.dijit.BookmarkItem({name:_c.name,extent:_e});this.bookmarks.push(_d);}var _f;if(this.editable){var _10=esri.bundle.widgets.bookmarks;console.log(_10);var _11=_10.NLS_bookmark_edit;var _12=_10.NLS_bookmark_remove;_f=_4.create("div",{innerHTML:"<div class='esriBookmarkLabel'>"+_c.name+"</div><div title='"+_12+"' class='esriBookmarkRemoveImage'><br/></div><div title='"+_11+"' class='esriBookmarkEditImage'><br/></div>"});var _13=_4.query(".esriBookmarkEditImage",_f)[0];var _14=_4.query(".esriBookmarkRemoveImage",_f)[0];this._removeHandlers.push(_4.connect(_14,"onclick",this,"_removeBookmark"));this._editHandlers.push(_4.connect(_13,"onclick",this,"_editBookmarkLabel"));}else{_f=_4.create("div",{innerHTML:"<div class='esriBookmarkLabel' style='width: 210px;'>"+_c.name+"</div>"});}_4.addClass(_f,"esriBookmarkItem");var _15;if(_c.extent.declaredClass=="esri.geometry.Extent"){_15=_c.extent;}else{_15=new esri.geometry.Extent(_c.extent);}var _16=_4.query(".esriBookmarkLabel",_f)[0];this._clickHandlers.push(_4.connect(_16,"onclick",_4.hitch(this,"_onClickHandler",_c)));this._mouseOverHandlers.push(_4.connect(_f,"onmouseover",function(){_4.addClass(this,"esriBookmarkHighlight");}));this._mouseOutHandlers.push(_4.connect(_f,"onmouseout",function(){_4.removeClass(this,"esriBookmarkHighlight");}));var _17=this.bookmarkTable;var _18;if(this.editable){_18=_17.rows.length-1;}else{_18=_17.rows.length;}var _19=_17.insertRow(_18);var _1a=_19.insertCell(0);_1a.appendChild(_f);},removeBookmark:function(_1b){var _1c=_4.query(".esriBookmarkLabel",this.bookmarkDomNode);var _1d=_4.filter(_1c,function(_1e){return _1e.innerHTML==_1b;});_4.forEach(_1d,function(_1f){_1f.parentNode.parentNode.parentNode.parentNode.removeChild(_1f.parentNode.parentNode.parentNode);});for(var i=this.bookmarks.length-1;i>=0;i--){if(this.bookmarks[i].name==_1b){this.bookmarks.splice(i,1);}}this.onRemove();},hide:function(){esri.hide(this.bookmarkDomNode);},show:function(){esri.show(this.bookmarkDomNode);},destroy:function(){this.map=null;_4.forEach(this._clickHandlers,function(_20,idx){_4.disconnect(_20);});_4.forEach(this._mouseOverHandlers,function(_21,idx){_4.disconnect(_21);});_4.forEach(this._mouseOutHandlers,function(_22,idx){_4.disconnect(_22);});_4.forEach(this._removeHandlers,function(_23,idx){_4.disconnect(_23);});_4.forEach(this._editHandlers,function(_24,idx){_4.disconnect(_24);});_4.destroy(this.bookmarkDomNode);},toJson:function(){var _25=[];_4.forEach(this.bookmarks,function(_26,idx){_25.push(_26.toJson());});return _25;},_addInitialBookmarks:function(){if(this.editable){var _27=esri.bundle.widgets.bookmarks;var _28=_27.NLS_add_bookmark;var _29=_4.create("div",{innerHTML:"<div>"+_28+"</div>"});_4.addClass(_29,"esriBookmarkItem");_4.addClass(_29,"esriAddBookmark");this._clickHandlers.push(_4.connect(_29,"onclick",this,this._newBookmark));this._mouseOverHandlers.push(_4.connect(_29,"onmouseover",function(){_4.addClass(this,"esriBookmarkHighlight");}));this._mouseOutHandlers.push(_4.connect(_29,"onmouseout",function(){_4.removeClass(this,"esriBookmarkHighlight");}));var _2a=this.bookmarkTable;var _2b=_2a.insertRow(0);var _2c=_2b.insertCell(0);_2c.appendChild(_29);}this.bookmarks=[];_4.forEach(this.initBookmarks,function(_2d,idx){this.addBookmark(_2d);},this);},_removeBookmark:function(e){this.bookmarks.splice(e.target.parentNode.parentNode.parentNode.rowIndex,1);e.target.parentNode.parentNode.parentNode.parentNode.removeChild(e.target.parentNode.parentNode.parentNode);this.onRemove();},_editBookmarkLabel:function(e){var _2e=e.target.parentNode;var _2f=_4.position(_2e,true);var y=_2f.y;var _30=_4.create("div",{innerHTML:"<input type='text' class='esriBookmarkEditBox' style='left:"+_2f.x+"px; top:"+y+"px;'/>"});this._inputBox=_4.query("input",_30)[0];this._label=_4.query(".esriBookmarkLabel",_2e)[0];var _31=esri.bundle.widgets.bookmarks;var _32=_31.NLS_new_bookmark;if(this._label.innerHTML==_32){this._inputBox.value="";}else{this._inputBox.value=this._label.innerHTML;}_4.connect(this._inputBox,"onkeyup",this,function(key){switch(key.keyCode){case _4.keys.ENTER:this._finishEdit();break;default:break;}});_4.connect(this._inputBox,"onblur",this,"_finishEdit");_2e.appendChild(_30);this._inputBox.focus();},_finishEdit:function(){this._inputBox.parentNode.parentNode.removeChild(this._inputBox.parentNode);var _33=esri.bundle.widgets.bookmarks;var _34=_33.NLS_new_bookmark;if(this._inputBox.value==""){this._label.innerHTML=_34;}else{this._label.innerHTML=this._inputBox.value;}var _35=_4.query(".esriBookmarkLabel",this.bookmarkDomNode);_4.forEach(this.bookmarks,function(_36,idx){_36.name=_35[idx].innerHTML;});this.onEdit();},_newBookmark:function(){var _37=esri.bundle.widgets.bookmarks;var _38=_37.NLS_new_bookmark;var _39=new esri.dijit.BookmarkItem({"name":_38,"extent":this.map.extent});this.addBookmark(_39);var _3a=_4.query(".esriBookmarkItem",this.bookmarkDomNode);var _3b=_3a[_3a.length-2];var e={"target":{"parentNode":null}};e.target.parentNode=_3b;this._editBookmarkLabel(e);},_onClickHandler:function(_3c){var _3d=_3c.extent;if(!_3c.extent.declaredClass){_3d=new esri.geometry.Extent(_3c.extent);}this.map.setExtent(_3d);this.onClick();}});}}};});