/*
 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.PopupMobile"]){dojo._hasResource["esri.dijit.PopupMobile"]=true;dojo.provide("esri.dijit.PopupMobile");dojo.require("esri.InfoWindowBase");dojo.require("esri.PopupBase");dojo.require("esri.dijit.NavigationBar");dojo.require("esri.dijit.InfoView");dojo.require("dojo.number");dojo.require("dojo.date.locale");dojo.require("dojox.charting.Chart2D");dojo.require("dojox.charting.themes.PlotKit.base");dojo.require("dojox.charting.action2d.Tooltip");dojo.require("dojo.i18n");(function(){var dc=dojox.charting,pk=dc.themes.PlotKit;pk.popup=pk.base.clone();pk.popup.chart.fill=pk.popup.plotarea.fill="#e7eef6";pk.popup.colors=["#284B70","#702828","#5F7143","#F6BC0C","#382C6C","#50224F","#1D7554","#4C4C4C","#0271AE","#706E41","#446A73","#0C3E69","#757575","#B7B7B7","#A3A3A3"];pk.popup.series.stroke.width=1;pk.popup.marker.stroke.width=1;}());dojo.declare("esri.dijit.PopupMobile",[esri.InfoWindowBase,esri.PopupBase],{offsetX:3,offsetY:3,zoomFactor:4,marginLeft:10,marginTop:10,highlight:true,popupNavigationBar:null,popupInfoView:null,location:null,xIcon:dojo.moduleUrl("esri.dijit","./images/whitex.png"),dArrowIcon:dojo.moduleUrl("esri.dijit","./images/whitedown.png"),lArrowIcon:dojo.moduleUrl("esri.dijit","./images/whitel.png"),rArrowIcon:dojo.moduleUrl("esri.dijit","./images/whiter.png"),constructor:function(_1,_2){this.initialize();dojo.mixin(this,_1);this.domNode=dojo.byId(_2);var _3=this._nls=dojo.mixin({},esri.bundle.widgets.popup);var _4=this.domNode;dojo.addClass(_4,"esriPopupMobile");var _5="<div class='sizer'>"+"<div class='titlePane'>"+"<div class='spinner hidden'>"+"</div>"+"<div class='title'></div>"+"<div style='text-align:center'>"+"<div class='titleButton prev hidden'></div>"+"<div class='footer' style='display:inline-block;width:60px;height:15px;'></div>"+"<div class='titleButton next hidden'></div>"+"</div>"+"<div class='titleButton close'></div>"+"<div class='titleButton arrow hidden'></div>"+"</div>"+"</div>"+"<div class='pointer top hidden'></div>"+"<div class='pointer bottom hidden'></div>";dojo.attr(_4,"innerHTML",_5);var _6=dojo.query(".titlePane",_4)[0];this._arrowButton=dojo.query(".arrow",_6)[0];this._pointerTop=dojo.query(".top",_4)[0];this._pointerBottom=dojo.query(".bottom",_4)[0];this._title=dojo.query(".title",_6)[0];this._footer=dojo.query(".footer",_6)[0];this._prev=dojo.query(".prev",_6)[0];this._next=dojo.query(".next",_6)[0];this._spinner=dojo.query(".spinner",_6)[0];this._eventConnections=[dojo.connect(dojo.query(".close",_6)[0],"onclick",this,this.hide),dojo.connect(this._arrowButton,"onclick",this,this._toggleView),dojo.connect(this._prev,"onclick",this,function(){this.selectPrevious();this._updateUI();}),dojo.connect(this._next,"onclick",this,function(){this.selectNext();this._updateUI();})];this._initPopupNavigationBar();this._initPopupInfoView();esri.hide(_4);this.isShowing=false;},setMap:function(_7){this.inherited(arguments);dojo.place(this.domNode,_7.root);if(this.highlight){this.enableHighlight(_7);}},unsetMap:function(){this.disableHighlight(this.map);this.inherited(arguments);},setTitle:function(_8,_9){this.destroyDijits(this._title);this.place(_8,this._title);this.destroyDijits(this._footer);this.place(_9,this._footer);if(this.isShowing){this.startupDijits(this._title);this.startupDijits(this._footer);}},setContent:function(_a){this.destroyDijits(this._contentPane);this.place(_a,this._contentPane);this.startupDijits(this._contentPane);},show:function(_b){if(!_b){esri.show(this.domNode);this.isShowing=true;return;}var _c=this.map,_d;if(_b.spatialReference){this._location=_b;_d=_c.toScreen(_b);}else{this._location=_c.toMap(_b);_d=_b;}if(this._maximized){this.restore();}else{this._setPosition(_d);}if(!this.isShowing){esri.show(this.domNode);this.isShowing=true;this.onShow();}},hide:function(){if(this.isShowing){esri.hide(this.domNode);this.isShowing=false;this.onHide();}},onShow:function(){this._followMap();this.startupDijits(this._title);this.showHighlight();},onHide:function(){this._unfollowMap();this.hideHighlight();},destroy:function(){if(this.map){this.unsetMap();}this.cleanup();if(this.isShowing){this.hide();}this.destroyDijits(this._title);this.destroyDijits(this._footer);dojo.forEach(this._eventConnections,dojo.disconnect);dojo.destroy(this.domNode);},selectNext:function(){this.select(this.selectedIndex+1);},selectPrevious:function(){this.select(this.selectedIndex-1);},setFeatures:function(){this.inherited(arguments);this._updateUI();},onSetFeatures:function(){},onClearFeatures:function(){this.setTitle("&nbsp;","&nbsp;");dojo.addClass(this._arrowButton,"hidden");this._updateUI();this.hideHighlight();},onSelectionChange:function(){var _e=this.selectedIndex;this._updateUI();if(_e>=0){this.setContent(this.features[_e].getContent());this.updateHighlight(this.map,this.features[_e]);if(this.isShowing){this.showHighlight();}}},onDfdComplete:function(){this._updateUI();},_followMap:function(){this._unfollowMap();var _f=this.map;this._handles=[dojo.connect(_f,"onPanStart",this,this._onPanStart),dojo.connect(_f,"onPan",this,this._onPan),dojo.connect(_f,"onZoomStart",this,this._onZoomStart),dojo.connect(_f,"onExtentChange",this,this._onExtentChange)];},_unfollowMap:function(){var _10=this._handles;if(_10){dojo.forEach(_10,dojo.disconnect,dojo);this._handles=null;}},_onPanStart:function(){var _11=this.domNode.style;this._panOrigin={left:_11.left,top:_11.top,right:_11.right,bottom:_11.bottom};},_onPan:function(_12,_13){var _14=this._panOrigin,dx=_13.x,dy=_13.y,_15=_14.left,top=_14.top,_16=_14.right,_17=_14.bottom;if(_15){_15=(parseFloat(_15)+dx)+"px";}if(top){top=(parseFloat(top)+dy)+"px";}if(_16){_16=(parseFloat(_16)-dx)+"px";}if(_17){_17=(parseFloat(_17)-dy)+"px";}dojo.style(this.domNode,{left:_15,top:top,right:_16,bottom:_17});},_onZoomStart:function(){esri.hide(this.domNode);},_onExtentChange:function(_18,_19,_1a){if(_1a){esri.show(this.domNode);this.show(this._targetLocation||this._location);this._targetLocation=null;}},_setPosition:function(_1b){var _1c=_1b.x,_1d=_1b.y,_1e=dojo.contentBox(this.map.container),_1f=_1e.w,_20=_1e.h;var _21=0,_22=_1d+10,_23=118,_24=18,_25=_1f-_24;if(_1c>_24&&_1c<_25){_21=_1c-130;if(_21<0){_21=0;}else{if(_21>_1f-260){_21=_1f-260;}}}else{if(_1c<=_24){_21=_1c-_24;}else{if(_1c>=_25){_21=(_1f-260)+(_1c-_25);}}}if(_1c>118&&_1c<_1f-130){_23=118;}else{if(_1c<=118){if(_1c>_24){_23=_1c-12;}else{if(_1c<=_24){_23=6;}}}else{if(_1c>=_1f-130){if(_1c<_25){_23=118+_1c-(_1f-130);}else{if(_1c>=_25){_23=118+(_25)-(_1f-130);}}}}}if(_1d<=_20/2){dojo.style(this.domNode,{left:_21+"px",top:_22+"px",bottom:null});dojo.style(this._pointerTop,{left:_23+"px"});dojo.addClass(this._pointerBottom,"hidden");dojo.removeClass(this._pointerTop,"hidden");}else{dojo.style(this.domNode,{left:_21+"px",top:_22-64+"px",bottom:null});dojo.style(this._pointerBottom,{left:_23+"px"});dojo.addClass(this._pointerTop,"hidden");dojo.removeClass(this._pointerBottom,"hidden");}},_showPointer:function(_26){var _27=["topLeft","topRight","bottomRight","bottomLeft"];dojo.forEach(_27,function(ptr){if(ptr===_26){dojo.query(".pointer."+ptr,this.domNode).removeClass("hidden");}else{dojo.query(".pointer."+ptr,this.domNode).addClass("hidden");}},this);},_toggleView:function(){if(!this.popupNavigationBar){this._initPopupNavigationBar();}if(!this.popupInfoView){this._initPopupInfoView();}this.hide();esri.show(this.popupNavigationBar.container);esri.show(this.popupInfoView.container);var _28="";if(this.selectedIndex>=0){_28=(this.selectedIndex+1)+" of "+this.features.length;this.setContent(this.features[this.selectedIndex].getContent());}},_handleNavigationBar:function(_29){this.popupInfoView.animateTo(0);switch(_29.name){case "CloseButton":esri.hide(this.popupNavigationBar.container);esri.hide(this.popupInfoView.container);this.hide();break;case "ToggleButton":esri.hide(this.popupNavigationBar.container);esri.hide(this.popupInfoView.container);this.show(this._location);break;case "PreviousButton":this.selectPrevious();this._updateUI();break;case "NextButton":this.selectNext();this._updateUI();break;}},_initPopupNavigationBar:function(){var _2a={};_2a.items=[{name:"CloseButton",type:"img",src:this.xIcon,srcAlt:this.xIcon,position:"left"},{name:"Title",type:"span",text:"",position:"center"},{name:"ToggleButton",type:"img",src:this.dArrowIcon,srcAlt:this.dArrowIcon,position:"right",toggleGroup:"toggle"},{name:"PreviousButton",type:"img",src:this.lArrowIcon,srcAlt:this.lArrowIcon,position:"right2",toggleGroup:"previous"},{name:"NextButton",type:"img",src:this.rArrowIcon,srcAlt:this.rArrowIcon,position:"right1",toggleGroup:"next"}];this.popupNavigationBar=new esri.dijit.NavigationBar(_2a,dojo.create("div",{},dojo.body()));dojo.connect(this.popupNavigationBar,"onCreate",this,function(_2b){this._prevFeatureButton=_2b[3]._node;this._nextFeatureButton=_2b[4]._node;});dojo.connect(this.popupNavigationBar,"onSelect",this,this._handleNavigationBar);dojo.connect(this.popupNavigationBar,"onUnSelect",this,this._handleNavigationBar);this.popupNavigationBar.startup();esri.hide(this.popupNavigationBar.container);},_initPopupInfoView:function(){var _2c={items:[{name:"Navigator",type:"div",text:""},{name:"content",type:"div",text:""},{name:"attachment",type:"div",text:""}]};this.popupInfoView=new esri.dijit.InfoView(_2c,dojo.create("div",{},dojo.body()));dojo.addClass(this.popupInfoView.container,"esriMobilePopupInfoView");this.popupInfoView.enableTouchScroll();dojo.connect(this.popupInfoView,"onCreate",this,function(_2d){this._contentPane=_2d[1]._node;if(this.selectedIndex>=0){this.setContent(this.features[this.selectedIndex].getContent());}});dojo.connect(this.popupInfoView,"onSwipeLeft",this,function(){});dojo.connect(this.popupInfoView,"onSwipeRight",this,function(){});this.popupInfoView.startup();},_updateUI:function(){var _2e="&nbsp;",_2f="&nbsp;",ptr=this.selectedIndex,_30=this.features,_31=this.deferreds,_32=this._prevFeatureButton.parentNode,_33=this._nextFeatureButton.parentNode,_34=this._spinner,_35=this._actionList,nls=this._nls;if(_30&&_30.length>=1){_2e=_30[ptr].getTitle();_2f=(ptr+1)+" of "+_30.length;dojo.removeClass(this._arrowButton,"hidden");if(ptr===0){dojo.addClass(_32,"hidden");dojo.addClass(this._prev,"hidden");}else{dojo.removeClass(_32,"hidden");dojo.removeClass(this._prev,"hidden");}if(ptr===_30.length-1){dojo.addClass(_33,"hidden");dojo.addClass(this._next,"hidden");}else{dojo.removeClass(_33,"hidden");dojo.removeClass(this._next,"hidden");}}else{dojo.addClass(this._arrowButton,"hidden");dojo.addClass(_32,"hidden");dojo.addClass(_33,"hidden");dojo.addClass(this._prev,"hidden");dojo.addClass(this._next,"hidden");}this.setTitle(_2e,_2f);this.popupNavigationBar.getItems()[1]._node.innerHTML=_2f;if(_31&&_31.length){dojo.removeClass(_34,"hidden");this.setTitle(nls.NLS_searching+"...","&nbsp;");}else{dojo.addClass(_34,"hidden");if(!_30||!_30.length){this.setTitle("No Information","&nbsp;");}}}});}