(function(e){var j="mousemove",d="mouseup",b="position",g="relative",c="left",a="top",h=".",l=window,i=document,m="html",k="body",f=function(n,o){return parseInt(n.css(o))};e.fn.makeDraggable=function(n){var p=null,r="MakeDraggable",t="1.02",o=j+h+r,s=d+h+r,q,w={horizontally:1,vertically:1,offsetLeft:0,offsetTop:0,restrictToZone:1,onMove:function(){}},v=function(A,D,y,B,C){var z=D<0?y:D<B?null:y-B+C;if(z){e.fn["scroll"+A].call(e(m),z)}},u=function(E,F,G,B,z,x,C,D){if(E){var y=F-q[G]+q[B],A=f(p,z);y=x<y?C>y?y:C:x;if(!(F<0&&A<y)&&!(F>D&&A>y)){return p.css(z,y),1}else{q[G]=F<0?0:D;q[B]=A}}return 0};if(n){e.extend(w,n)}return this.each(function(){var y=e(this),x=w.dragHandle?y.find(w.dragHandle):y;x.mousedown(function(B){p=y;var C=w.containment?e(w.containment):p.parent(),L=C.is(k),G=L?{top:0,left:0}:C.position(),z=L?{width:e(i).width(),height:e(i).height()}:{width:C.width(),height:C.height()},A=p.offset(),J=!L&&(C.css(b)==g),N=w.offsetLeft+J?0:G.left,D=w.offsetTop+J?0:G.top,F=N+z.width-(w.restrictToZone?p.outerWidth():0),K=D+z.height-(w.restrictToZone?p.outerHeight():0),M=e(l).width(),I=e(l).height(),H=f(p,c),E=f(p,a);q={eL:H||(H==0)?H:A.left,eT:E||(E==0)?E:A.top,mx:B.clientX,my:B.clientY};e(i).bind(o,function(Q){var R=p.offset(),O=Q.clientX,P=Q.clientY;v("Top",P,R.top,I,p.height());v("Left",O,R.left,M,p.width());var S=u(w.horizontally,O,"mx","eL",c,N,F,M);if(u(w.vertically,P,"my","eT",a,D,K,I)||S){w.onMove({left:f(p,c),top:f(p,a)})}}).bind(s,function(){e(i).unbind(o).unbind(s);p=null});return !1})})}})(jQuery);
