(function(){var e="",t="",n="",r="",i="",s="",o="",u="",a=1,f=25,l=10,c=0,h=10,p=!1,d=[0,0],v=0,m=1,g=!1,y=null,b=!0,w=!1;App.Utils.PanelSwipe={triggerVdownOnSwipablePanel:function(s,o,a){if((touchDevice||s.which==1)&&o!==undefined){s.preventDefault(),e="none",p=!0,t=this.getMouseX(s),n=this.getMouseY(s),u=0,r=0,i=0,y=o,w=a;if(y.classList.contains("swipablePanel")){showDebug==2&&console.log("updating limits of swipablePanel: "+y.id),y!==undefined&&(d=App.Utils.SwipablePanels[y.id].getLimits()),showDebug==2&&console.log("CloseLimit:"+d[v]+" /OpenLimit:"+d[m]);var f=$(y).hasClass("swipeX")?t:n;showDebug==2&&console.log("PANEL OPEN STATE: "+App.Utils.SwipablePanels[y.id].getState()),App.Utils.SwipablePanels[y.id].getState()===b?c=d[m]-f:c=d[v]-f,$(y).hasClass("swipeY")&&(c=Math.abs(c)),showDebug==2&&console.log("positionAdjust: "+c)}}},triggerVmoveOnSwipablePanel:function(h){if(p&&!app.Models.MainLayoutModel.get("deviceTray")){h.preventDefault();var b=o,w=s;s=this.getMouseX(h),o=this.getMouseY(h),r=s-t,i=o-n,Math.abs(r)>=f&&Math.abs(i)<=l&&(e=r<0?"swipeleft":"swiperight"),Math.abs(i)>=f&&Math.abs(r)<=l&&(e=i<0?"swipeup":"swipedown");var E,S,x,T;if(e=="swipeleft"||e=="swiperight")E=s,S=t,x=w,T=E+c;else if(e=="swipeup"||e=="swipedown")E=o,S=n,x=b,T=E+c;if(e=="swipeleft"||e=="swiperight")E>S?x>E?u+=x-E:u=0:E<S&&(x<E?u+=E-x:u=0),E<S&&(e=u>=a?"swiperight":"swipeleft");else if(e=="swipeup"||e=="swipedown"){T<d[m]?T=d[m]:T>d[v]&&(T=d[v]);var N=!1;if(T>S&&T>d[m]&&T<d[v])x>E?u+=x-E:u=0;else if(T<S&&T>d[m]&&T<d[v])x<E?u+=E-x:u=0;else if(T===d[v]||T===d[m])N=!0;N||(E<S?e=u<a?"swipeup":"swipedown":E>S&&(e=u<a?"swipedown":"swipeup"))}showDebug==2&&console.log("Swipe direction: "+e);switch(e){case"swipeleft":case"swiperight":if(y.classList.contains("swipeX")){s=s+c<=d[v]?d[v]:s,s=s+c>=d[m]?d[m]:s;if(d[m]>d[v]&&e=="swipeleft"||d[m]<d[m]&&e=="swiperight")g=!0;g&&(s!==d[v]&&s!==d[m]?this.animatePanel(s+c,!1):this.animatePanel(s,!1))}break;case"swipeup":case"swipedown":if(y.classList.contains("swipeY")){o=o-c>=d[v]?d[v]:o,o=o-c<=d[m]?d[m]:o;if(o!==d[v]&&o!==d[m]){var C=!0;n>=d[v]&&o>n&&(C=!1),C&&this.animatePanel(o-c,!1)}}}}},triggerVupOnSwipablePanel:function(t){if(p){t.preventDefault(),p=!1,g=!1;var n=$(y).data("backboneView"),s,o,u,a;d[m]>d[v]?(s=u=d[v],o=a=d[m]):(s=u=d[m],o=a=d[v]);switch(e){case"swipeleft":case"swiperight":y.classList.contains("swipeX")?e=="swipeleft"?App.Utils.SwipablePanels[y.id].swipePanel(s,!0,e):App.Utils.SwipablePanels[y.id].swipePanel(o,!0,e):console.log("Swipeleft/right ignored");break;case"swipeup":case"swipedown":y.classList.contains("swipeY")?e=="swipeup"?App.Utils.SwipablePanels[y.id].swipePanel(u,!0,e):App.Utils.SwipablePanels[y.id].swipePanel(a,!0,e):console.log("Swipeup/down ignored");break;case"none":y.classList.contains("swipeX")&&Math.abs(r)<h?App.Utils.SwipablePanels[y.id].swipePanel(null,null,e,w):y.classList.contains("swipeY")&&Math.abs(i)<h&&App.Utils.SwipablePanels[y.id].swipePanel(null,null,e)}}},animatePanel:function(t,n){var r=$(y),i=t-r.width()*.85;if(e=="swipeleft"||e=="swiperight")n?r.addClass("animate").css("transform",""):r.removeClass("animate").css("transform","translate3d("+i+"px,0,0)");else if(e=="swipeup"||e=="swipedown")n?r.addClass("animate").css("transform",""):r.removeClass("animate").css("transform","translate3d(0,"+t+"px,0)")},getMouseX:function(e){var t=e.pageX;return touchDevice&&(t=e.originalEvent.touches[0].pageX),t},getMouseY:function(e){var t=e.pageY;return touchDevice&&(t=e.originalEvent.touches[0].pageY),t},matrixToArray:function(e){return e.substr(7,e.length-8).split(", ")},setPanelMove:function(e){p=e}}})();