(function(b){function a(c,d){var e=b.browser.safari&&b.browser.version<522;if(c.contains&&!e){return c.contains(d);}if(c.compareDocumentPosition){return !!(c.compareDocumentPosition(d)&16);}while(d=d.parentNode){if(d==c){return true;}}return false;}b.widget("ui.sortable",b.extend({},b.ui.mouse,{init:function(){var c=this.options;
this.containerCache={};this.element.addClass("ui-sortable");this.refresh();this.floating=this.items.length?(/left|right/).test(this.items[0].item.css("float")):false;if(!(/(relative|absolute|fixed)/).test(this.element.css("position"))){this.element.css("position","relative");}this.offset=this.element.offset();
this.mouseInit();},plugins:{},ui:function(c){return{helper:(c||this)["helper"],placeholder:(c||this)["placeholder"]||b([]),position:(c||this)["position"],absolutePosition:(c||this)["positionAbs"],options:this.options,element:this.element,item:(c||this)["currentItem"],sender:c?c.element:null};},propagate:function(c,d,f,e){b.ui.plugin.call(this,c,[d,this.ui(f)]);
if(!e){this.element.triggerHandler(c=="sort"?c:"sort"+c,[d,this.ui(f)],this.options[c]);}},serialize:function(c){var e=(b.isFunction(this.options.items)?this.options.items.call(this.element):b(this.options.items,this.element)).not(".ui-sortable-helper");var d=[];c=c||{};e.each(function(){var f=(b(this).attr(c.attribute||"id")||"").match(c.expression||(/(.+)[-=_](.+)/));
if(f){d.push((c.key||f[1])+"[]="+(c.key&&c.expression?f[1]:f[2]));}});return d.join("&");},toArray:function(e){var d=(b.isFunction(this.options.items)?this.options.items.call(this.element):b(this.options.items,this.element)).not(".ui-sortable-helper");var c=[];d.each(function(){c.push(b(this).attr(e||"id"));
});return c;},intersectsWith:function(f){var k=this.positionAbs.left,c=k+this.helperProportions.width,g=this.positionAbs.top,h=g+this.helperProportions.height;var j=f.left,d=j+f.width,e=f.top,i=e+f.height;if(this.options.tolerance=="pointer"||this.options.forcePointerForContainers||(this.options.tolerance=="guess"&&this.helperProportions[this.floating?"width":"height"]>f[this.floating?"width":"height"])){return(g+this.offset.click.top>e&&g+this.offset.click.top<i&&k+this.offset.click.left>j&&k+this.offset.click.left<d);
}else{return(j<k+(this.helperProportions.width/2)&&c-(this.helperProportions.width/2)<d&&e<g+(this.helperProportions.height/2)&&h-(this.helperProportions.height/2)<i);}},intersectsWithEdge:function(f){var k=this.positionAbs.left,c=k+this.helperProportions.width,g=this.positionAbs.top,h=g+this.helperProportions.height;
var j=f.left,d=j+f.width,e=f.top,i=e+f.height;if(this.options.tolerance=="pointer"||(this.options.tolerance=="guess"&&this.helperProportions[this.floating?"width":"height"]>f[this.floating?"width":"height"])){if(!(g+this.offset.click.top>e&&g+this.offset.click.top<i&&k+this.offset.click.left>j&&k+this.offset.click.left<d)){return false;
}if(this.floating){if(k+this.offset.click.left>j&&k+this.offset.click.left<j+f.width/2){return 2;}if(k+this.offset.click.left>j+f.width/2&&k+this.offset.click.left<d){return 1;}}else{if(g+this.offset.click.top>e&&g+this.offset.click.top<e+f.height/2){return 2;}if(g+this.offset.click.top>e+f.height/2&&g+this.offset.click.top<i){return 1;
}}}else{if(!(j<k+(this.helperProportions.width/2)&&c-(this.helperProportions.width/2)<d&&e<g+(this.helperProportions.height/2)&&h-(this.helperProportions.height/2)<i)){return false;}if(this.floating){if(c>j&&k<j){return 2;}if(k<d&&c>d){return 1;}}else{if(h>e&&g<e){return 1;}if(g<i&&h>i){return 2;}}}return false;
},refresh:function(){this.refreshItems();this.refreshPositions();},refreshItems:function(){this.items=[];this.containers=[this];var h=this.items;var i=this;var f=[[b.isFunction(this.options.items)?this.options.items.call(this.element,null,{options:this.options,item:this.currentItem}):b(this.options.items,this.element),this]];
if(this.options.connectWith){for(var e=this.options.connectWith.length-1;e>=0;e--){var c=b(this.options.connectWith[e]);for(var g=c.length-1;g>=0;g--){var d=b.data(c[g],"sortable");if(d&&!d.options.disabled){f.push([b.isFunction(d.options.items)?d.options.items.call(d.element):b(d.options.items,d.element),d]);
this.containers.push(d);}}}}for(var e=f.length-1;e>=0;e--){f[e][0].each(function(){b.data(this,"sortable-item",f[e][1]);h.push({item:b(this),instance:f[e][1],width:0,height:0,left:0,top:0});});}},refreshPositions:function(f){if(this.offsetParent){var g=this.offsetParent.offset();this.offset.parent={top:g.top+this.offsetParentBorders.top,left:g.left+this.offsetParentBorders.left};
}for(var d=this.items.length-1;d>=0;d--){if(this.items[d].instance!=this.currentContainer&&this.currentContainer&&this.items[d].item[0]!=this.currentItem[0]){continue;}var e=this.options.toleranceElement?b(this.options.toleranceElement,this.items[d].item):this.items[d].item;if(!f){this.items[d].width=e[0].offsetWidth;
this.items[d].height=e[0].offsetHeight;}var c=e.offset();this.items[d].left=c.left;this.items[d].top=c.top;}if(this.options.custom&&this.options.custom.refreshContainers){this.options.custom.refreshContainers.call(this);}else{for(var d=this.containers.length-1;d>=0;d--){var c=this.containers[d].element.offset();
this.containers[d].containerCache.left=c.left;this.containers[d].containerCache.top=c.top;this.containers[d].containerCache.width=this.containers[d].element.outerWidth();this.containers[d].containerCache.height=this.containers[d].element.outerHeight();}}},destroy:function(){this.element.removeClass("ui-sortable ui-sortable-disabled").removeData("sortable").unbind(".sortable");
this.mouseDestroy();for(var c=this.items.length-1;c>=0;c--){this.items[c].item.removeData("sortable-item");}},createPlaceholder:function(d){var f=d||this,c=f.options;if(c.placeholder.constructor==String){var e=c.placeholder;c.placeholder={element:function(){return b("<div></div>").addClass(e)[0];},update:function(h,g){g.css(h.offset()).css({width:h.outerWidth(),height:h.outerHeight()});
}};}f.placeholder=b(c.placeholder.element.call(f.element,f.currentItem)).appendTo("body").css({position:"absolute"});c.placeholder.update.call(f.element,f.currentItem,f.placeholder);},contactContainers:function(f){for(var h=this.containers.length-1;h>=0;h--){if(this.intersectsWith(this.containers[h].containerCache)){if(!this.containers[h].containerCache.over){if(this.currentContainer!=this.containers[h]){var c=10000;
var d=null;var g=this.positionAbs[this.containers[h].floating?"left":"top"];for(var i=this.items.length-1;i>=0;i--){if(!a(this.containers[h].element[0],this.items[i].item[0])){continue;}var e=this.items[i][this.containers[h].floating?"left":"top"];if(Math.abs(e-g)<c){c=Math.abs(e-g);d=this.items[i];}}if(!d&&!this.options.dropOnEmpty){continue;
}if(this.placeholder){this.placeholder.remove();}if(this.containers[h].options.placeholder){this.containers[h].createPlaceholder(this);}else{this.placeholder=null;}this.currentContainer=this.containers[h];d?this.rearrange(f,d,null,true):this.rearrange(f,null,this.containers[h].element,true);this.propagate("change",f);
this.containers[h].propagate("change",f,this);}this.containers[h].propagate("over",f,this);this.containers[h].containerCache.over=1;}}else{if(this.containers[h].containerCache.over){this.containers[h].propagate("out",f,this);this.containers[h].containerCache.over=0;}}}},mouseCapture:function(d,e){if(this.options.disabled||this.options.type=="static"){return false;
}this.refreshItems();var f=null,g=this,h=b(d.target).parents().each(function(){if(b.data(this,"sortable-item")==g){f=b(this);return false;}});if(b.data(d.target,"sortable-item")==g){f=b(d.target);}if(!f){return false;}if(this.options.handle&&!e){var c=false;b(this.options.handle,f).find("*").andSelf().each(function(){if(this==d.target){c=true;
}});if(!c){return false;}}this.currentItem=f;return true;},mouseStart:function(e,g,j){var c=this.options;this.currentContainer=this;this.refreshPositions();this.helper=typeof c.helper=="function"?b(c.helper.apply(this.element[0],[e,this.currentItem])):this.currentItem.clone();if(!this.helper.parents("body").length){b(c.appendTo!="parent"?c.appendTo:this.currentItem[0].parentNode)[0].appendChild(this.helper[0]);
}this.helper.css({position:"absolute",clear:"both"}).addClass("ui-sortable-helper");this.margins={left:(parseInt(this.currentItem.css("marginLeft"),10)||0),top:(parseInt(this.currentItem.css("marginTop"),10)||0)};this.offset=this.currentItem.offset();this.offset={top:this.offset.top-this.margins.top,left:this.offset.left-this.margins.left};
this.offset.click={left:e.pageX-this.offset.left,top:e.pageY-this.offset.top};this.offsetParent=this.helper.offsetParent();var i=this.offsetParent.offset();this.offsetParentBorders={top:(parseInt(this.offsetParent.css("borderTopWidth"),10)||0),left:(parseInt(this.offsetParent.css("borderLeftWidth"),10)||0)};
this.offset.parent={top:i.top+this.offsetParentBorders.top,left:i.left+this.offsetParentBorders.left};this.originalPosition=this.generatePosition(e);this.domPosition={prev:this.currentItem.prev()[0],parent:this.currentItem.parent()[0]};this.helperProportions={width:this.helper.outerWidth(),height:this.helper.outerHeight()};
if(c.placeholder){this.createPlaceholder();}this.propagate("start",e);this.helperProportions={width:this.helper.outerWidth(),height:this.helper.outerHeight()};if(c.cursorAt){if(c.cursorAt.left!=undefined){this.offset.click.left=c.cursorAt.left;}if(c.cursorAt.right!=undefined){this.offset.click.left=this.helperProportions.width-c.cursorAt.right;
}if(c.cursorAt.top!=undefined){this.offset.click.top=c.cursorAt.top;}if(c.cursorAt.bottom!=undefined){this.offset.click.top=this.helperProportions.height-c.cursorAt.bottom;}}if(c.containment){if(c.containment=="parent"){c.containment=this.helper[0].parentNode;}if(c.containment=="document"||c.containment=="window"){this.containment=[0-this.offset.parent.left,0-this.offset.parent.top,b(c.containment=="document"?document:window).width()-this.offset.parent.left-this.helperProportions.width-this.margins.left-(parseInt(this.element.css("marginRight"),10)||0),(b(c.containment=="document"?document:window).height()||document.body.parentNode.scrollHeight)-this.offset.parent.top-this.helperProportions.height-this.margins.top-(parseInt(this.element.css("marginBottom"),10)||0)];
}if(!(/^(document|window|parent)$/).test(c.containment)){var f=b(c.containment)[0];var d=b(c.containment).offset();this.containment=[d.left+(parseInt(b(f).css("borderLeftWidth"),10)||0)-this.offset.parent.left,d.top+(parseInt(b(f).css("borderTopWidth"),10)||0)-this.offset.parent.top,d.left+Math.max(f.scrollWidth,f.offsetWidth)-(parseInt(b(f).css("borderLeftWidth"),10)||0)-this.offset.parent.left-this.helperProportions.width-this.margins.left-(parseInt(this.currentItem.css("marginRight"),10)||0),d.top+Math.max(f.scrollHeight,f.offsetHeight)-(parseInt(b(f).css("borderTopWidth"),10)||0)-this.offset.parent.top-this.helperProportions.height-this.margins.top-(parseInt(this.currentItem.css("marginBottom"),10)||0)];
}}if(this.options.placeholder!="clone"){this.currentItem.css("visibility","hidden");}if(!j){for(var h=this.containers.length-1;h>=0;h--){this.containers[h].propagate("activate",e,this);}}if(b.ui.ddmanager){b.ui.ddmanager.current=this;}if(b.ui.ddmanager&&!c.dropBehaviour){b.ui.ddmanager.prepareOffsets(this,e);
}this.dragging=true;this.mouseDrag(e);return true;},convertPositionTo:function(d,c){if(!c){c=this.position;}var e=d=="absolute"?1:-1;return{top:(c.top+this.offset.parent.top*e-(this.offsetParent[0]==document.body?0:this.offsetParent[0].scrollTop)*e+this.margins.top*e),left:(c.left+this.offset.parent.left*e-(this.offsetParent[0]==document.body?0:this.offsetParent[0].scrollLeft)*e+this.margins.left*e)};
},generatePosition:function(d){var c=this.options;var g={top:(d.pageY-this.offset.click.top-this.offset.parent.top+(this.offsetParent[0]==document.body?0:this.offsetParent[0].scrollTop)),left:(d.pageX-this.offset.click.left-this.offset.parent.left+(this.offsetParent[0]==document.body?0:this.offsetParent[0].scrollLeft))};
if(!this.originalPosition){return g;}if(this.containment){if(g.left<this.containment[0]){g.left=this.containment[0];}if(g.top<this.containment[1]){g.top=this.containment[1];}if(g.left>this.containment[2]){g.left=this.containment[2];}if(g.top>this.containment[3]){g.top=this.containment[3];}}if(c.grid){var e=this.originalPosition.top+Math.round((g.top-this.originalPosition.top)/c.grid[1])*c.grid[1];
g.top=this.containment?(!(e<this.containment[1]||e>this.containment[3])?e:(!(e<this.containment[1])?e-c.grid[1]:e+c.grid[1])):e;var f=this.originalPosition.left+Math.round((g.left-this.originalPosition.left)/c.grid[0])*c.grid[0];g.left=this.containment?(!(f<this.containment[0]||f>this.containment[2])?f:(!(f<this.containment[0])?f-c.grid[0]:f+c.grid[0])):f;
}return g;},mouseDrag:function(d){this.position=this.generatePosition(d);this.positionAbs=this.convertPositionTo("absolute");b.ui.plugin.call(this,"sort",[d,this.ui()]);this.positionAbs=this.convertPositionTo("absolute");this.helper[0].style.left=this.position.left+"px";this.helper[0].style.top=this.position.top+"px";
for(var e=this.items.length-1;e>=0;e--){var c=this.intersectsWithEdge(this.items[e]);if(!c){continue;}if(this.items[e].item[0]!=this.currentItem[0]&&this.currentItem[c==1?"next":"prev"]()[0]!=this.items[e].item[0]&&!a(this.currentItem[0],this.items[e].item[0])&&(this.options.type=="semi-dynamic"?!a(this.element[0],this.items[e].item[0]):true)){this.direction=c==1?"down":"up";
this.rearrange(d,this.items[e]);this.propagate("change",d);break;}}this.contactContainers(d);if(b.ui.ddmanager){b.ui.ddmanager.drag(this,d);}this.element.triggerHandler("sort",[d,this.ui()],this.options["sort"]);return false;},rearrange:function(c,d,g,e){g?g[0].appendChild(this.currentItem[0]):d.item[0].parentNode.insertBefore(this.currentItem[0],(this.direction=="down"?d.item[0]:d.item[0].nextSibling));
this.counter=this.counter?++this.counter:1;var f=this,h=this.counter;window.setTimeout(function(){if(h==f.counter){f.refreshPositions(!e);}},0);if(this.options.placeholder){this.options.placeholder.update.call(this.element,this.currentItem,this.placeholder);}},mouseStop:function(d,e){if(b.ui.ddmanager&&!this.options.dropBehaviour){b.ui.ddmanager.drop(this,d);
}if(this.options.revert){var f=this;var c=f.currentItem.offset();if(f.placeholder){f.placeholder.animate({opacity:"hide"},(parseInt(this.options.revert,10)||500)-50);}b(this.helper).animate({left:c.left-this.offset.parent.left-f.margins.left+(this.offsetParent[0]==document.body?0:this.offsetParent[0].scrollLeft),top:c.top-this.offset.parent.top-f.margins.top+(this.offsetParent[0]==document.body?0:this.offsetParent[0].scrollTop)},parseInt(this.options.revert,10)||500,function(){f.clear(d);
});}else{this.clear(d,e);}return false;},clear:function(c,d){if(this.domPosition.prev!=this.currentItem.prev().not(".ui-sortable-helper")[0]||this.domPosition.parent!=this.currentItem.parent()[0]){this.propagate("update",c,null,d);}if(!a(this.element[0],this.currentItem[0])){this.propagate("remove",c,null,d);
for(var e=this.containers.length-1;e>=0;e--){if(a(this.containers[e].element[0],this.currentItem[0])){this.containers[e].propagate("update",c,this,d);this.containers[e].propagate("receive",c,this,d);}}}for(var e=this.containers.length-1;e>=0;e--){this.containers[e].propagate("deactivate",c,this,d);if(this.containers[e].containerCache.over){this.containers[e].propagate("out",c,this);
this.containers[e].containerCache.over=0;}}this.dragging=false;if(this.cancelHelperRemoval){this.propagate("stop",c,null,d);return false;}b(this.currentItem).css("visibility","");if(this.placeholder){this.placeholder.remove();}this.helper.remove();this.helper=null;this.propagate("stop",c,null,d);return true;
}}));b.extend(b.ui.sortable,{getter:"serialize toArray",defaults:{helper:"clone",tolerance:"guess",distance:1,delay:0,scroll:true,scrollSensitivity:20,scrollSpeed:20,cancel:":input",items:"> *",zIndex:1000,dropOnEmpty:true,appendTo:"parent"}});b.ui.plugin.add("sortable","cursor",{start:function(c,d){var e=b("body");
if(e.css("cursor")){d.options._cursor=e.css("cursor");}e.css("cursor",d.options.cursor);},stop:function(c,d){if(d.options._cursor){b("body").css("cursor",d.options._cursor);}}});b.ui.plugin.add("sortable","zIndex",{start:function(c,d){var e=d.helper;if(e.css("zIndex")){d.options._zIndex=e.css("zIndex");
}e.css("zIndex",d.options.zIndex);},stop:function(c,d){if(d.options._zIndex){b(d.helper).css("zIndex",d.options._zIndex);}}});b.ui.plugin.add("sortable","opacity",{start:function(c,d){var e=d.helper;if(e.css("opacity")){d.options._opacity=e.css("opacity");}e.css("opacity",d.options.opacity);},stop:function(c,d){if(d.options._opacity){b(d.helper).css("opacity",d.options._opacity);
}}});b.ui.plugin.add("sortable","scroll",{start:function(d,e){var c=e.options;var f=b(this).data("sortable");f.overflowY=function(g){do{if(/auto|scroll/.test(g.css("overflow"))||(/auto|scroll/).test(g.css("overflow-y"))){return g;}g=g.parent();}while(g[0].parentNode);return b(document);}(f.currentItem);
f.overflowX=function(g){do{if(/auto|scroll/.test(g.css("overflow"))||(/auto|scroll/).test(g.css("overflow-x"))){return g;}g=g.parent();}while(g[0].parentNode);return b(document);}(f.currentItem);if(f.overflowY[0]!=document&&f.overflowY[0].tagName!="HTML"){f.overflowYOffset=f.overflowY.offset();}if(f.overflowX[0]!=document&&f.overflowX[0].tagName!="HTML"){f.overflowXOffset=f.overflowX.offset();
}},sort:function(d,e){var c=e.options;var f=b(this).data("sortable");if(f.overflowY[0]!=document&&f.overflowY[0].tagName!="HTML"){if((f.overflowYOffset.top+f.overflowY[0].offsetHeight)-d.pageY<c.scrollSensitivity){f.overflowY[0].scrollTop=f.overflowY[0].scrollTop+c.scrollSpeed;}if(d.pageY-f.overflowYOffset.top<c.scrollSensitivity){f.overflowY[0].scrollTop=f.overflowY[0].scrollTop-c.scrollSpeed;
}}else{if(d.pageY-b(document).scrollTop()<c.scrollSensitivity){b(document).scrollTop(b(document).scrollTop()-c.scrollSpeed);}if(b(window).height()-(d.pageY-b(document).scrollTop())<c.scrollSensitivity){b(document).scrollTop(b(document).scrollTop()+c.scrollSpeed);}}if(f.overflowX[0]!=document&&f.overflowX[0].tagName!="HTML"){if((f.overflowXOffset.left+f.overflowX[0].offsetWidth)-d.pageX<c.scrollSensitivity){f.overflowX[0].scrollLeft=f.overflowX[0].scrollLeft+c.scrollSpeed;
}if(d.pageX-f.overflowXOffset.left<c.scrollSensitivity){f.overflowX[0].scrollLeft=f.overflowX[0].scrollLeft-c.scrollSpeed;}}else{if(d.pageX-b(document).scrollLeft()<c.scrollSensitivity){b(document).scrollLeft(b(document).scrollLeft()-c.scrollSpeed);}if(b(window).width()-(d.pageX-b(document).scrollLeft())<c.scrollSensitivity){b(document).scrollLeft(b(document).scrollLeft()+c.scrollSpeed);
}}}});b.ui.plugin.add("sortable","axis",{sort:function(c,d){var e=b(this).data("sortable");if(d.options.axis=="y"){e.position.left=e.originalPosition.left;}if(d.options.axis=="x"){e.position.top=e.originalPosition.top;}}});})(jQuery);
