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