(function(a){a.widget("ui.draggable",a.extend({},a.ui.mouse,{init:function(){var b=this.options;if(b.helper=="original"&&!(/(relative|absolute|fixed)/).test(this.element.css("position"))){this.element.css("position","relative");}this.element.addClass("ui-draggable");(b.disabled&&this.element.addClass("ui-draggable-disabled"));
this.mouseInit();},mouseStart:function(d){var b=this.options;if(this.helper||b.disabled||a(d.target).is(".ui-resizable-handle")){return false;}var g=!this.options.handle||!a(this.options.handle,this.element).length?true:false;a(this.options.handle,this.element).find("*").andSelf().each(function(){if(this==d.target){g=true;
}});if(!g){return false;}if(a.ui.ddmanager){a.ui.ddmanager.current=this;}this.helper=a.isFunction(b.helper)?a(b.helper.apply(this.element[0],[d])):(b.helper=="clone"?this.element.clone():this.element);if(!this.helper.parents("body").length){this.helper.appendTo((b.appendTo=="parent"?this.element[0].parentNode:b.appendTo));
}if(this.helper[0]!=this.element[0]&&!(/(fixed|absolute)/).test(this.helper.css("position"))){this.helper.css("position","absolute");}this.margins={left:(parseInt(this.element.css("marginLeft"),10)||0),top:(parseInt(this.element.css("marginTop"),10)||0)};this.cssPosition=this.helper.css("position");this.offset=this.element.offset();
this.offset={top:this.offset.top-this.margins.top,left:this.offset.left-this.margins.left};this.offset.click={left:d.pageX-this.offset.left,top:d.pageY-this.offset.top};this.offsetParent=this.helper.offsetParent();var h=this.offsetParent.offset();if(this.offsetParent[0]==document.body&&a.browser.mozilla){h={top:0,left:0};
}this.offset.parent={top:h.top+(parseInt(this.offsetParent.css("borderTopWidth"),10)||0),left:h.left+(parseInt(this.offsetParent.css("borderLeftWidth"),10)||0)};var e=this.element.position();this.offset.relative=this.cssPosition=="relative"?{top:e.top-(parseInt(this.helper.css("top"),10)||0)+this.offsetParent[0].scrollTop,left:e.left-(parseInt(this.helper.css("left"),10)||0)+this.offsetParent[0].scrollLeft}:{top:0,left:0};
this.originalPosition=this.generatePosition(d);this.helperProportions={width:this.helper.outerWidth(),height:this.helper.outerHeight()};if(b.cursorAt){if(b.cursorAt.left!=undefined){this.offset.click.left=b.cursorAt.left+this.margins.left;}if(b.cursorAt.right!=undefined){this.offset.click.left=this.helperProportions.width-b.cursorAt.right+this.margins.left;
}if(b.cursorAt.top!=undefined){this.offset.click.top=b.cursorAt.top+this.margins.top;}if(b.cursorAt.bottom!=undefined){this.offset.click.top=this.helperProportions.height-b.cursorAt.bottom+this.margins.top;}}if(b.containment){if(b.containment=="parent"){b.containment=this.helper[0].parentNode;}if(b.containment=="document"||b.containment=="window"){this.containment=[0-this.offset.relative.left-this.offset.parent.left,0-this.offset.relative.top-this.offset.parent.top,a(b.containment=="document"?document:window).width()-this.offset.relative.left-this.offset.parent.left-this.helperProportions.width-this.margins.left-(parseInt(this.element.css("marginRight"),10)||0),(a(b.containment=="document"?document:window).height()||document.body.parentNode.scrollHeight)-this.offset.relative.top-this.offset.parent.top-this.helperProportions.height-this.margins.top-(parseInt(this.element.css("marginBottom"),10)||0)];
}if(!(/^(document|window|parent)$/).test(b.containment)){var f=a(b.containment)[0];var c=a(b.containment).offset();this.containment=[c.left+(parseInt(a(f).css("borderLeftWidth"),10)||0)-this.offset.relative.left-this.offset.parent.left,c.top+(parseInt(a(f).css("borderTopWidth"),10)||0)-this.offset.relative.top-this.offset.parent.top,c.left+Math.max(f.scrollWidth,f.offsetWidth)-(parseInt(a(f).css("borderLeftWidth"),10)||0)-this.offset.relative.left-this.offset.parent.left-this.helperProportions.width-this.margins.left-(parseInt(this.element.css("marginRight"),10)||0),c.top+Math.max(f.scrollHeight,f.offsetHeight)-(parseInt(a(f).css("borderTopWidth"),10)||0)-this.offset.relative.top-this.offset.parent.top-this.helperProportions.height-this.margins.top-(parseInt(this.element.css("marginBottom"),10)||0)];
}}this.propagate("start",d);this.helperProportions={width:this.helper.outerWidth(),height:this.helper.outerHeight()};if(a.ui.ddmanager&&!b.dropBehaviour){a.ui.ddmanager.prepareOffsets(this,d);}this.helper.addClass("ui-draggable-dragging");this.mouseDrag(d);return true;},convertPositionTo:function(c,b){if(!b){b=this.position;
}var d=c=="absolute"?1:-1;return{top:(b.top+this.offset.relative.top*d+this.offset.parent.top*d-(this.cssPosition=="fixed"||(this.cssPosition=="absolute"&&this.offsetParent[0]==document.body)?0:this.offsetParent[0].scrollTop)*d+(this.cssPosition=="fixed"?a(document).scrollTop():0)*d+this.margins.top*d),left:(b.left+this.offset.relative.left*d+this.offset.parent.left*d-(this.cssPosition=="fixed"||(this.cssPosition=="absolute"&&this.offsetParent[0]==document.body)?0:this.offsetParent[0].scrollLeft)*d+(this.cssPosition=="fixed"?a(document).scrollLeft():0)*d+this.margins.left*d)};
},generatePosition:function(c){var b=this.options;var f={top:(c.pageY-this.offset.click.top-this.offset.relative.top-this.offset.parent.top+(this.cssPosition=="fixed"||(this.cssPosition=="absolute"&&this.offsetParent[0]==document.body)?0:this.offsetParent[0].scrollTop)-(this.cssPosition=="fixed"?a(document).scrollTop():0)),left:(c.pageX-this.offset.click.left-this.offset.relative.left-this.offset.parent.left+(this.cssPosition=="fixed"||(this.cssPosition=="absolute"&&this.offsetParent[0]==document.body)?0:this.offsetParent[0].scrollLeft)-(this.cssPosition=="fixed"?a(document).scrollLeft():0))};
if(!this.originalPosition){return f;}if(this.containment){if(f.left<this.containment[0]){f.left=this.containment[0];}if(f.top<this.containment[1]){f.top=this.containment[1];}if(f.left>this.containment[2]){f.left=this.containment[2];}if(f.top>this.containment[3]){f.top=this.containment[3];}}if(b.grid){var d=this.originalPosition.top+Math.round((f.top-this.originalPosition.top)/b.grid[1])*b.grid[1];
f.top=this.containment?(!(d<this.containment[1]||d>this.containment[3])?d:(!(d<this.containment[1])?d-b.grid[1]:d+b.grid[1])):d;var e=this.originalPosition.left+Math.round((f.left-this.originalPosition.left)/b.grid[0])*b.grid[0];f.left=this.containment?(!(e<this.containment[0]||e>this.containment[2])?e:(!(e<this.containment[0])?e-b.grid[0]:e+b.grid[0])):e;
}return f;},mouseDrag:function(b){this.position=this.generatePosition(b);this.positionAbs=this.convertPositionTo("absolute");this.position=this.propagate("drag",b)||this.position;if(!this.options.axis||this.options.axis!="y"){this.helper[0].style.left=this.position.left+"px";}if(!this.options.axis||this.options.axis!="x"){this.helper[0].style.top=this.position.top+"px";
}if(a.ui.ddmanager){a.ui.ddmanager.drag(this,b);}return false;},mouseStop:function(c){var b=false;if(a.ui.ddmanager&&!this.options.dropBehaviour){var b=a.ui.ddmanager.drop(this,c);}if((this.options.revert=="invalid"&&!b)||(this.options.revert=="valid"&&b)||this.options.revert===true){var d=this;a(this.helper).animate(this.originalPosition,parseInt(this.options.revert,10)||500,function(){d.propagate("stop",c);
d.clear();});}else{this.propagate("stop",c);this.clear();}return false;},clear:function(){this.helper.removeClass("ui-draggable-dragging");if(this.options.helper!="original"&&!this.cancelHelperRemoval){this.helper.remove();}this.helper=null;this.cancelHelperRemoval=false;},plugins:{},uiHash:function(b){return{helper:this.helper,position:this.position,absolutePosition:this.positionAbs,options:this.options};
},propagate:function(b,c){a.ui.plugin.call(this,b,[c,this.uiHash()]);if(b=="drag"){this.positionAbs=this.convertPositionTo("absolute");}return this.element.triggerHandler(b=="drag"?b:"drag"+b,[c,this.uiHash()],this.options[b]);},destroy:function(){if(!this.element.data("draggable")){return;}this.element.removeData("draggable").unbind(".draggable").removeClass("ui-draggable");
this.mouseDestroy();}}));a.extend(a.ui.draggable,{defaults:{appendTo:"parent",axis:false,cancel:":input",delay:0,distance:1,helper:"original"}});a.ui.plugin.add("draggable","cursor",{start:function(b,c){var d=a("body");if(d.css("cursor")){c.options._cursor=d.css("cursor");}d.css("cursor",c.options.cursor);
},stop:function(b,c){if(c.options._cursor){a("body").css("cursor",c.options._cursor);}}});a.ui.plugin.add("draggable","zIndex",{start:function(b,c){var d=a(c.helper);if(d.css("zIndex")){c.options._zIndex=d.css("zIndex");}d.css("zIndex",c.options.zIndex);},stop:function(b,c){if(c.options._zIndex){a(c.helper).css("zIndex",c.options._zIndex);
}}});a.ui.plugin.add("draggable","opacity",{start:function(b,c){var d=a(c.helper);if(d.css("opacity")){c.options._opacity=d.css("opacity");}d.css("opacity",c.options.opacity);},stop:function(b,c){if(c.options._opacity){a(c.helper).css("opacity",c.options._opacity);}}});a.ui.plugin.add("draggable","iframeFix",{start:function(b,c){a(c.options.iframeFix===true?"iframe":c.options.iframeFix).each(function(){a('<div class="ui-draggable-iframeFix" style="background: #fff;"></div>').css({width:this.offsetWidth+"px",height:this.offsetHeight+"px",position:"absolute",opacity:"0.001",zIndex:1000}).css(a(this).offset()).appendTo("body");
});},stop:function(b,c){a("div.DragDropIframeFix").each(function(){this.parentNode.removeChild(this);});}});a.ui.plugin.add("draggable","scroll",{start:function(c,d){var b=d.options;var e=a(this).data("draggable");b.scrollSensitivity=b.scrollSensitivity||20;b.scrollSpeed=b.scrollSpeed||20;e.overflowY=function(f){do{if(/auto|scroll/.test(f.css("overflow"))||(/auto|scroll/).test(f.css("overflow-y"))){return f;
}f=f.parent();}while(f[0].parentNode);return a(document);}(this);e.overflowX=function(f){do{if(/auto|scroll/.test(f.css("overflow"))||(/auto|scroll/).test(f.css("overflow-x"))){return f;}f=f.parent();}while(f[0].parentNode);return a(document);}(this);if(e.overflowY[0]!=document&&e.overflowY[0].tagName!="HTML"){e.overflowYOffset=e.overflowY.offset();
}if(e.overflowX[0]!=document&&e.overflowX[0].tagName!="HTML"){e.overflowXOffset=e.overflowX.offset();}},drag:function(c,d){var b=d.options;var e=a(this).data("draggable");if(e.overflowY[0]!=document&&e.overflowY[0].tagName!="HTML"){if((e.overflowYOffset.top+e.overflowY[0].offsetHeight)-c.pageY<b.scrollSensitivity){e.overflowY[0].scrollTop=e.overflowY[0].scrollTop+b.scrollSpeed;
}if(c.pageY-e.overflowYOffset.top<b.scrollSensitivity){e.overflowY[0].scrollTop=e.overflowY[0].scrollTop-b.scrollSpeed;}}else{if(c.pageY-a(document).scrollTop()<b.scrollSensitivity){a(document).scrollTop(a(document).scrollTop()-b.scrollSpeed);}if(a(window).height()-(c.pageY-a(document).scrollTop())<b.scrollSensitivity){a(document).scrollTop(a(document).scrollTop()+b.scrollSpeed);
}}if(e.overflowX[0]!=document&&e.overflowX[0].tagName!="HTML"){if((e.overflowXOffset.left+e.overflowX[0].offsetWidth)-c.pageX<b.scrollSensitivity){e.overflowX[0].scrollLeft=e.overflowX[0].scrollLeft+b.scrollSpeed;}if(c.pageX-e.overflowXOffset.left<b.scrollSensitivity){e.overflowX[0].scrollLeft=e.overflowX[0].scrollLeft-b.scrollSpeed;
}}else{if(c.pageX-a(document).scrollLeft()<b.scrollSensitivity){a(document).scrollLeft(a(document).scrollLeft()-b.scrollSpeed);}if(a(window).width()-(c.pageX-a(document).scrollLeft())<b.scrollSensitivity){a(document).scrollLeft(a(document).scrollLeft()+b.scrollSpeed);}}}});a.ui.plugin.add("draggable","snap",{start:function(b,c){var d=a(this).data("draggable");
d.snapElements=[];a(c.options.snap===true?".ui-draggable":c.options.snap).each(function(){var e=a(this);var f=e.offset();if(this!=d.element[0]){d.snapElements.push({item:this,width:e.outerWidth(),height:e.outerHeight(),top:f.top,left:f.left});}});},drag:function(m,i){var n=a(this).data("draggable");var k=i.options.snapTolerance||20;
var b=i.absolutePosition.left,c=b+n.helperProportions.width,g=i.absolutePosition.top,h=g+n.helperProportions.height;for(var o=n.snapElements.length-1;o>=0;o--){var r=n.snapElements[o].left,d=r+n.snapElements[o].width,e=n.snapElements[o].top,j=e+n.snapElements[o].height;if(!((r-k<b&&b<d+k&&e-k<g&&g<j+k)||(r-k<b&&b<d+k&&e-k<h&&h<j+k)||(r-k<c&&c<d+k&&e-k<g&&g<j+k)||(r-k<c&&c<d+k&&e-k<h&&h<j+k))){continue;
}if(i.options.snapMode!="inner"){var l=Math.abs(e-h)<=20;var f=Math.abs(j-g)<=20;var p=Math.abs(r-c)<=20;var q=Math.abs(d-b)<=20;if(l){i.position.top=n.convertPositionTo("relative",{top:e-n.helperProportions.height,left:0}).top;}if(f){i.position.top=n.convertPositionTo("relative",{top:j,left:0}).top;
}if(p){i.position.left=n.convertPositionTo("relative",{top:0,left:r-n.helperProportions.width}).left;}if(q){i.position.left=n.convertPositionTo("relative",{top:0,left:d}).left;}}if(i.options.snapMode!="outer"){var l=Math.abs(e-g)<=20;var f=Math.abs(j-h)<=20;var p=Math.abs(r-b)<=20;var q=Math.abs(d-c)<=20;
if(l){i.position.top=n.convertPositionTo("relative",{top:e,left:0}).top;}if(f){i.position.top=n.convertPositionTo("relative",{top:j-n.helperProportions.height,left:0}).top;}if(p){i.position.left=n.convertPositionTo("relative",{top:0,left:r}).left;}if(q){i.position.left=n.convertPositionTo("relative",{top:0,left:d-n.helperProportions.width}).left;
}}}}});a.ui.plugin.add("draggable","connectToSortable",{start:function(b,c){var d=a(this).data("draggable");d.sortables=[];a(c.options.connectToSortable).each(function(){if(a.data(this,"sortable")){var e=a.data(this,"sortable");d.sortables.push({instance:e,shouldRevert:e.options.revert});e.refreshItems();
e.propagate("activate",b,d);}});},stop:function(b,c){var d=a(this).data("draggable");a.each(d.sortables,function(){if(this.instance.isOver){this.instance.isOver=0;d.cancelHelperRemoval=true;this.instance.cancelHelperRemoval=false;if(this.shouldRevert){this.instance.options.revert=true;}this.instance.mouseStop(b);
this.instance.element.triggerHandler("sortreceive",[b,a.extend(this.instance.ui(),{sender:d.element})],this.instance.options["receive"]);this.instance.options.helper=this.instance.options._helper;}else{this.instance.propagate("deactivate",b,d);}});},drag:function(b,c){var d=a(this).data("draggable"),f=this;
var e=function(g){var j=g.left,h=j+g.width,i=g.top,k=i+g.height;return(j<(this.positionAbs.left+this.offset.click.left)&&(this.positionAbs.left+this.offset.click.left)<h&&i<(this.positionAbs.top+this.offset.click.top)&&(this.positionAbs.top+this.offset.click.top)<k);};a.each(d.sortables,function(g){if(e.call(d,this.instance.containerCache)){if(!this.instance.isOver){this.instance.isOver=1;
this.instance.currentItem=a(f).clone().appendTo(this.instance.element).data("sortable-item",true);this.instance.options._helper=this.instance.options.helper;this.instance.options.helper=function(){return c.helper[0];};b.target=this.instance.currentItem[0];this.instance.mouseCapture(b,true);this.instance.mouseStart(b,true,true);
this.instance.offset.click.top=d.offset.click.top;this.instance.offset.click.left=d.offset.click.left;this.instance.offset.parent.left-=d.offset.parent.left-this.instance.offset.parent.left;this.instance.offset.parent.top-=d.offset.parent.top-this.instance.offset.parent.top;d.propagate("toSortable",b);
}if(this.instance.currentItem){this.instance.mouseDrag(b);}}else{if(this.instance.isOver){this.instance.isOver=0;this.instance.cancelHelperRemoval=true;this.instance.options.revert=false;this.instance.mouseStop(b,true);this.instance.options.helper=this.instance.options._helper;this.instance.currentItem.remove();
if(this.instance.placeholder){this.instance.placeholder.remove();}d.propagate("fromSortable",b);}}});}});a.ui.plugin.add("draggable","stack",{start:function(b,d){var c=a.makeArray(a(d.options.stack.group)).sort(function(e,f){return(parseInt(a(e).css("zIndex"),10)||d.options.stack.min)-(parseInt(a(f).css("zIndex"),10)||d.options.stack.min);
});a(c).each(function(e){this.style.zIndex=d.options.stack.min+e;});this[0].style.zIndex=d.options.stack.min+c.length;}});})(jQuery);
