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