define(["Ti/_/Evented","Ti/_/lang","Ti/UI","Ti/_/ready","Ti/_/event"],function(n,t,e,i,a){function o(){var n=!!(window.innerWidth&&window.innerWidth>window.innerHeight),t=l.__values__.constants;return t.orientation=n?e.LANDSCAPE_LEFT:e.PORTRAIT,t.landscape=n,t.portrait=!n,l.orientation}function r(n){var t=null,i=Math.abs(n.beta||0|n.y),a=Math.abs(n.gamma||0|n.x);5>i&&a>170&&(t=e.FACE_DOWN),5>i&&5>a&&(t=e.FACE_UP),i>50&&0>i&&u!=t&&(t=e.UPSIDE_PORTRAIT),null!==t&&u!==t&&l.fireEvent("orientationchange",{orientation:u=t,source:n.source})}var c=window,s=require.on,u=null,d=Date.now(),v={},f=0,h=[],l=t.setObject("Ti.Gesture",n,{_updateOrientation:function(){o(),u!==l.orientation&&l.fireEvent("orientationchange",{orientation:u=l.orientation})},addEventListener:function(t){"orientationchange"==t&&f++,1==f&&(h=[s(c,"MozOrientation",r),s(c,"deviceorientation",r)]),n.addEventListener.apply(this,arguments)},removeEventListener:function(t){"orientationchange"==t&&(f=Math.max(f-1,0)),0==f&&a.off(h),n.removeEventListener.apply(this,arguments)},isLandscape:function(){return l.landscape},isPortrait:function(){return l.portrait},constants:{portrait:!1,landscape:!1,orientation:e.UNKNOWN}});return i(function(){o()}),s(c,"devicemotion",function(n){var t,e,i,a,o=n.acceleration||n.accelerationIncludingGravity,r=o&&{x:o.x,y:o.y,z:o.z,source:n.source};r&&(void 0!==v.x&&(t=Math.abs(v.x-r.x)>10,e=Math.abs(v.y-r.y)>10,i=Math.abs(v.z-r.z)>10,(t&&(e||i)||e&&i)&&(a=Date.now(),(r.timestamp=a-d)>300&&(d=a,l.fireEvent("shake",r)))),v=r)}),l});