(function(){function y(a,b,c){m=setTimeout(function(){m=null;11>zk.ie&&g&&g.node!=a.node||(g=a)},a.opts.delay);n=c}function t(){g=null;p&&setTimeout(function(){p=null},0)}function u(a){if(g&&!g.dead){var b=jq.Event.zk(a),c=[b.pageX,b.pageY];k&&k[0]==c[0]&&k[1]==c[1]||(k=c,g._updateDrag(c,b),a.stop())}}function v(a){m&&(clearTimeout(m),m=null);var b=jq.Event.zk(a),c=g;c?(k=g=null,c._endDrag(b),b.domStopped&&a.stop(),c._suicide&&(c._suicide=!1,c.destroy())):1==b.which&&(p=null)}function w(a){g&&g._keypress(a)}
function z(a){a=a.node;a._$opacity=jq(a).css("opacity");r[a]=!0;new zk.eff.Opacity(a,{duration:.2,from:a._$opacity,to:.7})}function A(a){var b=a.node;new zk.eff.Opacity(b,{duration:.2,from:.7,to:"number"==typeof b._$opacity?b._$opacity:1,queue:{scope:"_draggable",position:"end"},afterFinish:function(){delete r[b]}})}function B(a,b){var c,d;if((c=b[0])||(d=b[1])){var e=a.node,f=e.style.position;new zk.eff.Move(e,{x:-c,y:-d,duration:.02*Math.sqrt(Math.abs(d^2)+Math.abs(c^2)),queue:{scope:"_draggable",
position:"end"},afterFinish:function(){e.style.position=f}})}}function x(a){return jq.nodeName(a.target,"input","textarea")}var q=[],r={},m,l,g,n,p,k,h;zk.Draggable=zk.$extends(zk.Object,{$init:function(a,b,c){l||(jq(l=jq.newStackup(null,"z_ddstkup")).hide(),document.body.appendChild(l));this.control=a;this.node=b=b?jq(b,zk)[0]:a.node||(a.$n?a.$n():null);if(!b)throw"Handle required for "+a;c=zk.$default(c,{scrollSensitivity:20,scrollSpeed:15,initSensitivity:3,delay:0,fireOnMove:!0});null==c.reverteffect&&
(c.reverteffect=B);null==c.endeffect&&(c.endeffect=A,null==c.starteffect&&(c.starteffect=z));c.handle&&(this.handle=jq(c.handle,zk)[0]);this.handle||(this.handle=b);!c.scroll||c.scroll.scrollTo||c.scroll.outerHTML||(c.scroll=jq(c.scroll,zk)[0],this._isScrollChild=zUtl.isAncestor(c.scroll,b));this.delta=this._currentDelta();this.opts=c;this.dragging=!1;jq(this.handle).bind("zmousedown",this.proxy(this._mousedown)).bind("dragstart",x);0==q.length&&jq(document).bind("zmouseup",v).bind("zmousemove",u).keypress(w);
q.push(this)},destroy:function(){this.dragging?this._suicide=!0:(jq(this.handle).unbind("zmousedown",this.proxy(this._mousedown)).unbind("dragstart",x),q.$remove(this),0==q.length&&jq(document).unbind("zmouseup",v).unbind("zmousemove",u).unbind("keypress",w),g==this&&(g=null),this.node=this.control=this.handle=null,this.dead=!0)},_currentDelta:function(){var a=jq(this.node);return[zk.parseInt(a.css("left")),zk.parseInt(a.css("top"))]},_startDrag:function(a){zWatch.fire("onStartDrag",this,a);zk(document.body).disableSelection();
jq.clearSelection();if(this.opts.overlay){var b=document.createElement("div");document.body.appendChild(b);b.className="z-dd-stackup";zk(b).disableSelection();b=(this.stackup=b).style;b.width=jq.px0(jq(document).width());b.height=jq.px0(jq(document).height())}zk.dragging=this.dragging=!0;b=this.node;if(opt=this.opts.ghosting)if("function"==typeof opt){this.delta=this._currentDelta();this.orgnode=this.node;b=zk(this.node);var c=b.cmOffset();this.z_scrl=b.scrollOffset();this.z_scrl[0]-=jq.innerX();
this.z_scrl[1]-=jq.innerY();c[0]-=this.z_scrl[0];c[1]-=this.z_scrl[1];b=this.node=opt(this,c,a)}else this._clone=jq(b).clone()[0],this.z_orgpos=b.style.position,"absolute"!=this.z_orgpos&&jq(b).absolutize(),b.parentNode.insertBefore(this._clone,b);this.opts.stackup&&(zk(l).isVisible()?this._stackup=jq.newStackup(b,b.id+"-ddstk"):(this._stackup=l,this._syncStackup(),b.parentNode.insertBefore(l,b)));this.orgZ=-1;if(opt=this.opts.zIndex)"function"==typeof opt&&(opt=opt(this)),0<=opt&&(this.orgZ=zk.parseInt(jq(b).css("z-index")),
b.style.zIndex=opt);this.opts.scroll&&(this.opts.scroll==window?(b=this._getWndScroll(this.opts.scroll),this.orgScrlLeft=b.left,this.orgScrlTop=b.top):(this.orgScrlLeft=this.opts.scroll.scrollLeft,this.orgScrlTop=this.opts.scroll.scrollTop));this.opts.starteffect&&this.opts.starteffect(this,a)},_syncStackup:function(){if(this._stackup){var a=this.node,b=this._stackup.style;b.display="block";b.left=a.offsetLeft+"px";b.top=a.offsetTop+"px";b.width=a.offsetWidth+"px";b.height=a.offsetHeight+"px"}},_updateDrag:function(a,
b){var c;if(!this.dragging){if((c=this.opts.initSensitivity)&&a[0]<=n[0]+c&&a[0]>=n[0]-c&&a[1]<=n[1]+c&&a[1]>=n[1]-c)return;this._startDrag(b)}this._updateInnerOfs();this._draw(a,b);this.opts.change&&this.opts.change(this,a,b);this._syncStackup();if(this.opts.scroll){this._stopScrolling();if(this.opts.scroll==window){c=this._getWndScroll(this.opts.scroll);var d=[c.left,c.top,c.left+c.width,c.top+c.height]}else d=zk(this.opts.scroll).viewportOffset(),d[0]+=this.opts.scroll.scrollLeft+this._innerOfs[0],
d[1]+=this.opts.scroll.scrollTop+this._innerOfs[1],d.push(d[0]+this.opts.scroll.offsetWidth),d.push(d[1]+this.opts.scroll.offsetHeight);var e=[0,0];c=this.opts.scrollSensitivity;a[0]<d[0]+c&&(e[0]=a[0]-(d[0]+c));a[1]<d[1]+c&&(e[1]=a[1]-(d[1]+c));a[0]>d[2]-c&&(e[0]=a[0]-(d[2]-c));a[1]>d[3]-c&&(e[1]=a[1]-(d[3]-c));this._startScrolling(e)}0<navigator.appVersion.indexOf("AppleWebKit")&&window.scrollBy(0,0);b.stop()},_finishDrag:function(a,b){this.dragging=!1;this.stackup&&(jq(this.stackup).remove(),delete this.stackup);
zk(document.body).enableSelection();setTimeout(jq.clearSelection,0);if(b=this._stackup)b==l?jq(b).hide():jq(b).remove(),delete this._stackup;b=this.node;this.opts.ghosting&&("function"==typeof this.opts.ghosting?(this.opts.endghosting&&this.opts.endghosting(this,this.orgnode),b!=this.orgnode&&(jq(b).remove(),this.node=this.orgnode),delete this.orgnode):("absolute"!=this.z_orgpos&&(zk(this.node).relativize(),b.style.position=this.z_orgpos),jq(this._clone).remove(),this._clone=null));var c=[a.pageX,
a.pageY],d=this.opts.revert;d&&"function"==typeof d&&(d=d(this,c,a));c=this._currentDelta();var e=this.delta;d&&this.opts.reverteffect?this.opts.reverteffect(this,[c[0]-this.delta[0],c[1]-this.delta[1]]):this.delta=c;-1!=this.orgZ&&(b.style.zIndex=this.orgZ);this.opts.endeffect&&this.opts.endeffect(this,a);d=this.control;this.opts.fireOnMove&&zk.Widget.isInstance(d)&&(c[0]==e[0]&&c[1]==e[1]||d.fire("onMove",zk.copy({left:b.style.left,top:b.style.top},a.data),{ignorable:!0}));t(this);var f=this;setTimeout(function(){zk.dragging=
!1;zWatch.fire("onEndDrag",f,a)},zk.ios?500:0)},_mousedown:function(a){var b=this.node,c=jq.Event.zk(a),d=a.target;if(!(m||r[b]||1!=c.which||zk.webkit&&jq.nodeName(d,"select")||zk(d).isInput()&&this.control!=zk.Widget.$(d)))if(d=[c.pageX,c.pageY],this.opts.ignoredrag&&this.opts.ignoredrag(this,d,c))c.domStopped&&a.stop();else{c=zk(b);var e=c.cmOffset();e=[d[0]-e[0],d[1]-e[1]];var f=jq.borders,g;(g=b.clientWidth)&&e[0]>g+c.sumStyles("l",f)&&e[0]<b.offsetWidth-c.sumStyles("r",f)||(g=b.clientHeight)&&
e[1]>g+c.sumStyles("t",f)&&e[1]<b.offsetHeight-c.sumStyles("b",f)||(this.offset=e,y(this,a,d),zk.mobile||(p=jq.Event.zk(a,this.control)))}},_keypress:function(a){27==a.keyCode&&(this._finishDrag(jq.Event.zk(a),!1),a.stop())},_endDrag:function(a){this.dragging?(this._stopScrolling(),this._finishDrag(a,!0),a.stop()):t(this)},_draw:function(a,b){var c=this.node,d=zk(c),e=d.cmOffset(),f=this.opts;f.ghosting&&(d=d.scrollOffset(),e[0]+=d[0]-this._innerOfs[0],e[1]+=d[1]-this._innerOfs[1]);d=this._currentDelta();
var g=f.scroll;e[0]-=d[0];e[1]-=d[1];g&&g!=window&&this._isScrollChild&&(e[0]-=g.scrollLeft-this.orgScrlLeft,e[1]-=g.scrollTop-this.orgScrlTop);a=[a[0]-e[0]-this.offset[0],a[1]-e[1]-this.offset[1]];(e=f.snap)&&(a="function"==typeof e?e(this,a):e instanceof Array?[Math.round(a[0]/e[0])*e[0],Math.round(a[1]/e[1])*e[1]]:[Math.round(a[0]/e)*e,Math.round(a[1]/e)*e]);this.z_scrl&&(a[0]-=this.z_scrl[0],a[1]-=this.z_scrl[1]);c=c.style;"function"==typeof f.draw?f.draw(this,this.snap_(a,f),b):"function"==typeof f.constraint?
((b=f.constraint(this,a,b))&&(a=b),a=this.snap_(a,f),c.left=jq.px(a[0]),c.top=jq.px(a[1])):(a=this.snap_(a,f),f.constraint&&"horizontal"!=f.constraint||(c.left=jq.px(a[0])),f.constraint&&"vertical"!=f.constraint||(c.top=jq.px(a[1])));"hidden"==c.visibility&&(c.visibility="")},_stopScrolling:function(){this.scrollInterval&&(clearInterval(this.scrollInterval),h=this.scrollInterval=null)},_startScrolling:function(a){if(a[0]||a[1])this.scrollSpeed=[a[0]*this.opts.scrollSpeed,a[1]*this.opts.scrollSpeed],
this.lastScrolled=new Date,this.scrollInterval=setInterval(this.proxy(this._scroll),10)},_scroll:function(){var a=new Date,b=a-this.lastScrolled;this.lastScrolled=a;if(this.opts.scroll==window){if(this.scrollSpeed[0]||this.scrollSpeed[1]){a=this._getWndScroll(this.opts.scroll);var c=b/1E3;this.opts.scroll.scrollTo(a.left+c*this.scrollSpeed[0],a.top+c*this.scrollSpeed[1])}}else this.opts.scroll.scrollLeft+=this.scrollSpeed[0]*b/1E3,this.opts.scroll.scrollTop+=this.scrollSpeed[1]*b/1E3;this._updateInnerOfs();
this._isScrollChild&&(h=h||k,h[0]+=this.scrollSpeed[0]*b/1E3,h[1]+=this.scrollSpeed[1]*b/1E3,0>h[0]&&(h[0]=0),0>h[1]&&(h[1]=0),this._draw(h));this.opts.change&&(b=(b=window.event?jq.event.fix(window.event):null)?jq.Event.zk(b):null,this.opts.change(this,b?[b.pageX,b.pageY]:k,b))},_updateInnerOfs:function(){this._innerOfs=[jq.innerX(),jq.innerY()]},_getWndScroll:function(a){var b=a.document,c=b.documentElement;if(c&&c.scrollTop){var d=c.scrollTop;var e=c.scrollLeft}else a.document.body&&(d=b.body.scrollTop,
e=b.body.scrollLeft);if(a.innerWidth){var f=a.innerWidth;a=a.innerHeight}else c&&c.clientWidth?(f=c.clientWidth,a=c.clientHeight):(f=b.body.offsetWidth,a=b.body.offsetHeight);return{top:d,left:e,width:f,height:a}},snap_:function(a,b){!b.snap&&0>a[1]&&(a[1]=0);return a}},{ignoreMouseUp:function(){return zk.dragging?!0:p},ignoreClick:function(){return zk.dragging},ignoreStop:function(a){return!1}})})();
