/*
 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.InfoView"]){dojo._hasResource["esri.dijit.InfoView"]=true;dojo.provide("esri.dijit.InfoView");dojo.require("esri.dijit._TouchBase");dojo.declare("esri.dijit.InfoView",null,{_items:[],_top:null,_sections:[],_isDecelerate:false,constructor:function(_1,_2){this.container=dojo.byId(_2);this._touchBase=esri.dijit._TouchBase(this.container,null);this._slideDiv=dojo.create("div",null,this.container,"first");this.events=[];this._items=_1.items;if(_1.sections){this._sections=_1.sections;}dojo.addClass(this.container,"esriMobileInfoView");if(this._sections.length===0){dojo.create("div",{},this._slideDiv);}else{for(var i=0;i<this._sections.length;i++){var _3=dojo.create("div",{"class":"esriMobileInfoViewSection"},this._slideDiv);dojo.create("div",{innerHTML:this._sections[i].title},_3);}}for(var i=0;i<this._items.length;i++){var _4,_5;var _6=0;if(this._items[i].section){_6=this._items[i].section;}switch(this._items[i].type){case "div":_5=dojo.create("div",{"class":"esriMobileInfoViewItem",style:this._items[i].style},this._slideDiv.childNodes[_6]);_4=dojo.create("div",{innerHTML:this._items[i].text},_5);break;}if(this._items[i].className){dojo.addClass(_4,this._items[i].className);}_4._index=i;_4._item=this._items[i];this._items[i]._node=_4;}this.startTouchY=0;},startup:function(){this.onCreate(this._items);this._animateTo(0);},destroy:function(){dojo.forEach(this.events,dojo.disconnect);this._touchBase=null;dojo.query("img",this.container).forEach(function(_7){_7._index=null;_7._item=null;dojo.destroy(_7);_7=null;});this._items=null;dojo.destroy(this._slideDiv);dojo.destroy(this.container);this.container=this._slideDiv=null;},getItems:function(){return this._items;},setPreventDefault:function(_8){this._touchBase.setPreventDefault(_8);},enableTouchScroll:function(){this._touchBase.setPreventDefault(true);this.events.push(dojo.connect(this._touchBase,"onTouchStart",this,this._onTouchStartHandler));this.events.push(dojo.connect(this._touchBase,"onTouchMove",this,this._onTouchMoveHandler));this.events.push(dojo.connect(this._touchBase,"onTouchEnd",this,this._onTouchEndHandler));this._slideDiv.style.webkitTransform="translate3d(0,"+this._top+"px, 0)";},disableTouchScroll:function(){dojo.disconnect(this.events.pop());dojo.disconnect(this.events.pop());dojo.disconnect(this.events.pop());this._touchBase.setPreventDefault(false);this._slideDiv.style.webkitTransform="translate3d(0, 0px, 0)";},animateTo:function(){this._slideDiv.style.WebkitTransitionDuration="0s";this._animateTo(0);},onSelect:function(_9){},onUnSelect:function(_a){},onCreate:function(_b){},onClick:function(e){},onSwipeLeft:function(){},onSwipeRight:function(){},_onTouchStartHandler:function(e){this._slideDiv.style.WebkitTransitionDuration="0s";this._moveDirection=null;this._startTime=new Date();this.startTouchY=e.touches[0].clientY;this.contentStartOffsetY=this.contentOffsetY;},_onTouchMoveHandler:function(e){if(!this._moveDirection){if(Math.abs(e.curY)>Math.abs(e.curX)){this._moveDirection="vertical";}else{this._moveDirection="horizontal";}}if(this._moveDirection==="horizontal"){return;}else{if(this._moveDirection==="vertical"){var _c=e.touches[0].clientY;var _d=_c-this.startTouchY;var _e=_d+this.contentStartOffsetY;this._animateTo(_e);}}},_onTouchEndHandler:function(e){this._endTime=new Date();this._deltaMovement=e.curY;if(this._moveDirection==="vertical"){if(this._shouldStartMomentum()){this._doMomentum();}else{this._snapToBounds();}}else{if(this._moveDirection==="horizontal"){if(e.swipeDirection==="left"){this.onSwipeLeft();}else{if(e.swipeDirection==="right"){this.onSwipeRight();}}}}},_shouldStartMomentum:function(){this._diff=this._endTime-this._startTime;this._velocity=this._deltaMovement/this._diff;if(Math.abs(this._velocity)>0.2&&this._diff<200){return true;}else{return false;}},_pullToStop:function(_f){if(Math.abs(_f)>80){_f=_f>0?80:(-contentBox.h+parentBox.h-10)-80;}console.log(_f);this._slideDiv.style.webkitTransition="-webkit-transform 200ms cubic-bezier(0, 0, 1, 1)";var _10=dojo.connect(this._slideDiv,"webkitTransitionEnd",this,function(){if(_f>0){this._animateTo(0);}else{this._animateTo(-contentBox.h+parentBox.h-10);}dojo.disconnect(_10);});this._animateTo(_f);},_doMomentum:function(){var _11=dojo.contentBox(this.container);var _12=this._velocity<0?0.001:-0.001;var _13=-(this._velocity*this._velocity)/(2*_12);var _14=-this._velocity/_12;var p0={x:0,y:0};var p1={x:0,y:0.3};var p2={x:0.6,y:1};var p3={x:1,y:1};var cx=3*(p1.x-p0.x);var bx=3*(p2.x-p1.x)-cx;var ax=p3.x-p0.x-cx-bx;var cy=3*(p1.y-p0.y);var by=3*(p2.y-p1.y)-cy;var ay=p3.y-p0.y-cy-by;var _15=0,_16=0;if(_11.h>this._slideDiv.scrollHeight){this.contentOffsetY=0;_16=300;}else{if(this.contentOffsetY+_13>0){for(var i=0,il=Math.floor(_14/20);i<il;i++){_15=(ax*(i*20)^3)+(bx*(i*20)^2)+cx*(i*20)+p0.x;_15=this._velocity<0?-_15:_15;if(this.contentOffsetY+_15>0){_16=i*20;break;}}if(_16===0){_16=300;}this.contentOffsetY=0;}else{if(Math.abs(this.contentOffsetY+_13)+_11.h>this._slideDiv.scrollHeight){this.contentOffsetY=_11.h-this._slideDiv.scrollHeight;for(var i=0,il=Math.floor(_14/20);i<il;i++){_15=(ax*(i*20)^3)+(bx*(i*20)^2)+cx*(i*20)+p0.x;_15=this._velocity<0?-_15:_15;if(Math.abs(this.contentOffsetY+_15)>this._slideDiv.scrollHeight){_16=i*20;break;}}}else{_16=_14;this.contentOffsetY=this.contentOffsetY+_13;}}}this._slideDiv.style.webkitTransition="-webkit-transform "+_16+"ms cubic-bezier(0, 0.3, 0.6, 1)";this._animateTo(this.contentOffsetY);},_snapToBounds:function(){var _17=dojo.contentBox(this.container);if(_17.h>this._slideDiv.scrollHeight){this.contentOffsetY=0;}else{if(this.contentOffsetY>0){this.contentOffsetY=0;}else{if(Math.abs(this.contentOffsetY)+_17.h>this._slideDiv.scrollHeight){this.contentOffsetY=_17.h-this._slideDiv.scrollHeight;}}}this._slideDiv.style.WebkitTransitionDuration="0.5s";this._animateTo(this.contentOffsetY);},_animateTo:function(_18){this.contentOffsetY=_18;this._slideDiv.style.webkitTransform="translate3d(0, "+_18+"px, 0)";},_stopMomentum:function(){if(this._isDecelerating()){var _19=document.defaultView.getComputedStyle(this._slideDiv,null);var _1a=new WebKitCSSMatrix(_19.webkitTransform);this._slideDiv.style.webkitTransition="";this.animateTo(_1a.m42);}},_isDecelerating:function(){if(this.isDecelerate){return true;}else{return false;}},_toggleNode:function(_1b,_1c){if(_1c.toggleState==="ON"){_1c.toggleState="OFF";if(_1c.src){_1b.src=_1c.src.toString();}this.onUnSelect(_1c);}else{_1c.toggleState="ON";if(_1c.srcAlt){_1b.src=_1c.srcAlt;}this.onSelect(_1c);}}});}