(function($){if(window.Node&&Node.prototype&&!Node.prototype.contains)Node.prototype.contains=function($){return!!(this.compareDocumentPosition($)&16)};$.fn.extend({sortable:function(A){var _=Array.prototype.slice.call(arguments,1);if(A=="serialize"||A=="toArray")return $.data(this[0],"sortable")[A](arguments[1]);return this.each(function(){if(typeof A=="string"){var B=$.data(this,"sortable");if(B)B[A].apply(B,_)}else if(!$.data(this,"sortable"))new $.ui.sortable(this,A)})}});$.ui.sortable=function(A,C){var B=this;this.element=$(A);this.containerCache={};$.data(A,"sortable",this);this.element.addClass("ui-sortable");this.options=$.extend({},C);var _=this.options;$.extend(_,{items:this.options.items||"> *",zIndex:this.options.zIndex||1000,startCondition:function(){return!B.options.disabled}});$(A).bind("setData.sortable",function(A,$,_){B.options[$]=_}).bind("getData.sortable",function(_,$){return B.options[$]});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.element.mouseInteraction({executor:this,delay:_.delay,distance:_.distance||0,dragPrevention:_.prevention?_.prevention.toLowerCase().split(","):["input","textarea","button","select","option"],start:this.start,stop:this.stop,drag:this.drag,condition:function(C){if(this.options.disabled||this.options.type=="static")return false;var _=null,A=$(C.target).parents().each(function(){if($.data(this,"sortable-item")){_=$(this);return false}});if($.data(C.target,"sortable-item"))_=$(C.target);if(!_)return false;if(this.options.handle){var B=false;$(this.options.handle,_).each(function(){if(this==C.target)B=true});if(!B)return false}this.currentItem=_;return true}});if(_.cursorAt&&_.cursorAt.constructor==Array)_.cursorAt={left:_.cursorAt[0],top:_.cursorAt[1]}};$.extend($.ui.sortable.prototype,{plugins:{},ui:function(_){return{helper:(_||this)["helper"],placeholder:(_||this)["placeholder"]||$([]),position:(_||this)["position"].current,absolutePosition:(_||this)["position"].absolute,instance:this,options:this.options,element:this.element,item:(_||this)["currentItem"],sender:_?_.element:null}},propagate:function(A,B,_){$.ui.plugin.call(this,A,[B,this.ui(_)]);this.element.triggerHandler(A=="sort"?A:"sort"+A,[B,this.ui(_)],this.options[A])},serialize:function(_){var A=$(this.options.items,this.element).not(".ui-sortable-helper"),B=[];_=_||{};A.each(function(){var A=($(this).attr(_.attribute||"id")||"").match(_.expression||(/(.+)[-=_](.+)/));if(A)B.push((_.key||A[1])+"[]="+(_.key?A[1]:A[2]))});return B.join("&")},toArray:function(A){var _=$(this.options.items,this.element).not(".ui-sortable-helper"),B=[];_.each(function(){B.push($(this).attr(A||"id"))});return B},enable:function(){this.element.removeClass("ui-sortable-disabled");this.options.disabled=false},disable:function(){this.element.addClass("ui-sortable-disabled");this.options.disabled=true},intersectsWith:function($){var D=this.position.absolute.left,_=D+this.helperProportions.width,F=this.position.absolute.top,C=F+this.helperProportions.height,E=$.left,A=E+$.width,B=$.top,G=B+$.height;return(E<D+(this.helperProportions.width/2)&&_-(this.helperProportions.width/2)<A&&B<F+(this.helperProportions.height/2)&&C-(this.helperProportions.height/2)<G)},intersectsWithEdge:function($){var D=this.position.absolute.left,_=D+this.helperProportions.width,F=this.position.absolute.top,C=F+this.helperProportions.height,E=$.left,A=E+$.width,B=$.top,G=B+$.height;if(!(E<D+(this.helperProportions.width/2)&&_-(this.helperProportions.width/2)<A&&B<F+(this.helperProportions.height/2)&&C-(this.helperProportions.height/2)<G))return false;if(this.floating){if(_>E&&D<E)return 2;if(D<A&&_>A)return 1}else{if(C>B&&F<B)return 1;if(F<G&&C>G)return 2}return false},inEmptyZone:function(B){if(!$(B.options.items,B.element).length)return B.options.dropOnEmpty?true:false;var _=$(B.options.items,B.element).not(".ui-sortable-helper");_=$(_[_.length-1]);var A=_.offset()[this.floating?"left":"top"]+_[0][this.floating?"offsetWidth":"offsetHeight"];return(this.position.absolute[this.floating?"left":"top"]>A)},refresh:function(){this.refreshItems();this.refreshPositions()},refreshItems:function(){this.items=[];this.containers=[this];var B=this.items,E=[$(this.options.items,this.element)];if(this.options.connectWith)for(var _=this.options.connectWith.length-1;_>=0;_--){var C=$(this.options.connectWith[_]);for(var D=C.length-1;D>=0;D--){var A=$.data(C[D],"sortable");if(A&&!A.options.disabled){E.push($(A.options.items,A.element));this.containers.push(A)}}}for(_=E.length-1;_>=0;_--)E[_].each(function(){$.data(this,"sortable-item",true);B.push({item:$(this),width:0,height:0,left:0,top:0})})},refreshPositions:function(_){for(var $=this.items.length-1;$>=0;$--){if(!_)this.items[$].width=this.items[$].item.outerWidth();if(!_)this.items[$].height=this.items[$].item.outerHeight();var A=this.items[$].item.offset();this.items[$].left=A.left;this.items[$].top=A.top}for($=this.containers.length-1;$>=0;$--){A=this.containers[$].element.offset();this.containers[$].containerCache.left=A.left;this.containers[$].containerCache.top=A.top;this.containers[$].containerCache.width=this.containers[$].element.outerWidth();this.containers[$].containerCache.height=this.containers[$].element.outerHeight()}},destroy:function(){this.element.removeClass("ui-sortable ui-sortable-disabled").removeData("sortable").unbind(".sortable").removeMouseInteraction();for(var $=this.items.length-1;$>=0;$--)this.items[$].item.removeData("sortable-item")},createPlaceholder:function(_){(_||this).placeholderElement=this.options.placeholderElement?$(this.options.placeholderElement,(_||this).currentItem):(_||this).currentItem;(_||this).placeholder=$("<div></div>").addClass(this.options.placeholder).appendTo("body").css({position:"absolute"}).css((_||this).placeholderElement.offset()).css({width:(_||this).placeholderElement.outerWidth(),height:(_||this).placeholderElement.outerHeight()})},contactContainers:function(E){for(var _=this.containers.length-1;_>=0;_--)if(this.intersectsWith(this.containers[_].containerCache)){if(!this.containers[_].containerCache.over){if(this.currentContainer!=this.containers[_]){var D=10000,B=null,$=this.position.absolute[this.containers[_].floating?"left":"top"];for(var C=this.items.length-1;C>=0;C--){if(!this.containers[_].element[0].contains(this.items[C].item[0]))continue;var A=this.items[C][this.containers[_].floating?"left":"top"];if(Math.abs(A-$)<D){D=Math.abs(A-$);B=this.items[C]}}if(this.placeholder)this.placeholder.remove();if(this.containers[_].options.placeholder)this.containers[_].createPlaceholder(this);else{this.placeholder=null;this.placeholderElement=null}B?this.rearrange(E,B):this.rearrange(E,null,this.containers[_].element);this.propagate("change",E);this.containers[_].propagate("change",E,this);this.currentContainer=this.containers[_]}this.containers[_].propagate("over",E,this);this.containers[_].containerCache.over=1}}else if(this.containers[_].containerCache.over){this.containers[_].propagate("out",E,this);this.containers[_].containerCache.over=0}},start:function(C,B){var _=this.options;this.refresh();this.helper=typeof _.helper=="function"?$(_.helper.apply(this.element[0],[C,this.currentItem])):this.currentItem.clone();if(!this.helper.parents("body").length)this.helper.appendTo(_.appendTo||this.currentItem[0].parentNode);this.helper.css({position:"absolute",clear:"both"}).addClass("ui-sortable-helper");$.extend(this,{offsetParent:this.helper.offsetParent(),offsets:{absolute:this.currentItem.offset()},mouse:{start:{top:C.pageY,left:C.pageX}},margins:{top:parseInt(this.currentItem.css("marginTop"))||0,left:parseInt(this.currentItem.css("marginLeft"))||0}});this.offsets.parent=this.offsetParent.offset();this.clickOffset={left:C.pageX-this.offsets.absolute.left,top:C.pageY-this.offsets.absolute.top};this.originalPosition={left:this.offsets.absolute.left-this.offsets.parent.left-this.margins.left,top:this.offsets.absolute.top-this.offsets.parent.top-this.margins.top};this.offset={left:C.pageX-this.originalPosition.left,top:C.pageY-this.originalPosition.top};$.extend(this,{position:{current:{top:C.pageY-this.offset.top,left:C.pageX-this.offset.left},absolute:{left:C.pageX-this.clickOffset.left,top:C.pageY-this.clickOffset.top},dom:this.currentItem.prev()[0]}});if(_.placeholder)this.createPlaceholder();this.propagate("start",C);this.helperProportions={width:this.helper.outerWidth(),height:this.helper.outerHeight()};if(_.cursorAt){if(_.cursorAt.top!=undefined||_.cursorAt.bottom!=undefined){this.offset.top-=this.clickOffset.top-(_.cursorAt.top!=undefined?_.cursorAt.top:(this.helperProportions.height-_.cursorAt.bottom));this.clickOffset.top=(_.cursorAt.top!=undefined?_.cursorAt.top:(this.helperProportions.height-_.cursorAt.bottom))}if(_.cursorAt.left!=undefined||_.cursorAt.right!=undefined){this.offset.left-=this.clickOffset.left-(_.cursorAt.left!=undefined?_.cursorAt.left:(this.helperProportions.width-_.cursorAt.right));this.clickOffset.left=(_.cursorAt.left!=undefined?_.cursorAt.left:(this.helperProportions.width-_.cursorAt.right))}}if(this.options.placeholder!="clone")$(this.currentItem).css("visibility","hidden");for(var A=this.containers.length-1;A>=0;A--)this.containers[A].propagate("activate",C,this);if($.ui.ddmanager)$.ui.ddmanager.current=this;if($.ui.ddmanager&&!_.dropBehaviour)$.ui.ddmanager.prepareOffsets(this,C);this.dragging=true;return false},stop:function(A){this.propagate("stop",A);if(this.position.dom!=this.currentItem.prev()[0])this.propagate("update",A);if(!this.element[0].contains(this.currentItem[0])){this.propagate("remove",A);for(var _=this.containers.length-1;_>=0;_--)if(this.containers[_].element[0].contains(this.currentItem[0])){this.containers[_].propagate("update",A,this);this.containers[_].propagate("receive",A,this)}}for(_=this.containers.length-1;_>=0;_--){this.containers[_].propagate("deactivate",A,this);if(this.containers[_].containerCache.over){this.containers[_].propagate("out",A,this);this.containers[_].containerCache.over=0}}if($.ui.ddmanager&&!this.options.dropBehaviour)$.ui.ddmanager.drop(this,A);this.dragging=false;if(this.cancelHelperRemoval)return false;$(this.currentItem).css("visibility","");if(this.placeholder)this.placeholder.remove();this.helper.remove();checkRootSort();return false},drag:function(B){this.position.current={top:B.pageY-this.offset.top,left:B.pageX-this.offset.left};this.position.absolute={left:B.pageX-this.clickOffset.left,top:B.pageY-this.clickOffset.top};for(var _=this.items.length-1;_>=0;_--){var A=this.intersectsWithEdge(this.items[_]);if(!A)continue;if(this.items[_].item[0]!=this.currentItem[0]&&this.currentItem[A==1?"next":"prev"]()[0]!=this.items[_].item[0]&&!this.currentItem[0].contains(this.items[_].item[0])&&(this.options.type=="semi-dynamic"?!this.element[0].contains(this.items[_].item[0]):true)){this.direction=A==1?"down":"up";this.rearrange(B,this.items[_]);this.propagate("change",B);break}}this.contactContainers(B);if($.ui.ddmanager)$.ui.ddmanager.drag(this,B);this.propagate("sort",B);this.helper.css({left:this.position.current.left+"px",top:this.position.current.top+"px",border:"2px dotted #999"});return false},rearrange:function(A,$,_){_?_.append(this.currentItem):$.item[this.direction=="down"?"before":"after"](this.currentItem);this.refreshPositions(true);if(this.placeholderElement)this.placeholder.css(this.placeholderElement.offset())}});$.ui.plugin.add("sortable","cursor",{start:function(B,A){var _=$("body");if(_.css("cursor"))A.options._cursor=_.css("cursor");_.css("cursor",A.options.cursor)},stop:function(A,_){if(_.options._cursor)$("body").css("cursor",_.options._cursor)}});$.ui.plugin.add("sortable","zIndex",{start:function(A,_){var $=_.helper;if($.css("zIndex"))_.options._zIndex=$.css("zIndex");$.css("zIndex",_.options.zIndex)},stop:function(A,_){if(_.options._zIndex)$(_.helper).css("zIndex",_.options._zIndex)}});$.ui.plugin.add("sortable","opacity",{start:function(A,_){var $=_.helper;if($.css("opacity"))_.options._opacity=$.css("opacity");$.css("opacity",_.options.opacity)},stop:function(A,_){if(_.options._opacity)$(_.helper).css("opacity",_.options._opacity)}});$.ui.plugin.add("sortable","revert",{stop:function(C,B){var _=B.instance;_.cancelHelperRemoval=true;var A=_.currentItem.offset(),$=_.helper.offsetParent().offset();if(B.instance.options.zIndex)B.helper.css("zIndex",B.instance.options.zIndex);if(B.instance.placeholder)B.instance.placeholder.animate({opacity:"hide"},parseInt(B.options.revert,10)||500);B.helper.animate({left:A.left-$.left-_.margins.left,top:A.top-$.top-_.margins.top},parseInt(B.options.revert,10)||500,function(){_.currentItem.css("visibility","visible");window.setTimeout(function(){if(_.placeholder)_.placeholder.remove();_.helper.remove();if(B.options._zIndex)B.helper.css("zIndex",B.options._zIndex)},50)})}});$.ui.plugin.add("sortable","containment",{start:function(D,B){var _=B.options;if((_.containment.left!=undefined||_.containment.constructor==Array)&&!_._containment)return;if(!_._containment)_._containment=_.containment;if(_._containment=="parent")_._containment=this[0].parentNode;if(_._containment=="sortable")_._containment=this[0];if(_._containment=="document")_.containment=[0,0,$(document).width(),($(document).height()||document.body.parentNode.scrollHeight)];else{var C=$(_._containment),A=C.offset();_.containment=[A.left,A.top,A.left+(C.outerWidth()||C[0].scrollWidth),A.top+(C.outerHeight()||C[0].scrollHeight)]}},sort:function(H,F){var $=F.options,E=F.helper,D=$.containment,B=F.instance,G=(parseInt(B.offsetParent.css("borderLeftWidth"),10)||0),A=(parseInt(B.offsetParent.css("borderRightWidth"),10)||0),_=(parseInt(B.offsetParent.css("borderTopWidth"),10)||0),C=(parseInt(B.offsetParent.css("borderBottomWidth"),10)||0);if(D.constructor==Array){if((B.position.absolute.left<D[0]))B.position.current.left=D[0]-B.offsets.parent.left-B.margins.left;if((B.position.absolute.top<D[1]))B.position.current.top=D[1]-B.offsets.parent.top-B.margins.top;if(B.position.absolute.left-D[2]+B.helperProportions.width>=0)B.position.current.left=D[2]-B.offsets.parent.left-B.helperProportions.width-B.margins.left-G-A;if(B.position.absolute.top-D[3]+B.helperProportions.height>=0)B.position.current.top=D[3]-B.offsets.parent.top-B.helperProportions.height-B.margins.top-_-C}else{if((F.position.left<D.left))B.position.current.left=D.left;if((F.position.top<D.top))B.position.current.top=D.top;if(F.position.left-B.offsetParent.innerWidth()+B.helperProportions.width+D.right+G+A>=0)B.position.current.left=B.offsetParent.innerWidth()-B.helperProportions.width-D.right-G-A;if(F.position.top-B.offsetParent.innerHeight()+B.helperProportions.height+D.bottom+_+C>=0)B.position.current.top=B.offsetParent.innerHeight()-B.helperProportions.height-D.bottom-_-C}}});$.ui.plugin.add("sortable","axis",{sort:function(A,_){var $=_.options;if($.constraint)$.axis=$.constraint;$.axis=="x"?_.instance.position.top=_.instance.originalPosition.top:_.instance.position.left=_.instance.originalPosition.left}});$.ui.plugin.add("sortable","scroll",{start:function(B,A){var _=A.options;_.scrollSensitivity=_.scrollSensitivity||20;_.scrollSpeed=_.scrollSpeed||20;A.instance.overflowY=function(_){do{if((/auto|scroll/).test(_.css("overflow"))||(/auto|scroll/).test(_.css("overflow-y")))return _;_=_.parent()}while(_[0].parentNode);return $(document)}(this);A.instance.overflowX=function(_){do{if((/auto|scroll/).test(_.css("overflow"))||(/auto|scroll/).test(_.css("overflow-x")))return _;_=_.parent()}while(_[0].parentNode);return $(document)}(this);if(A.instance.overflowY[0]!=document&&A.instance.overflowY[0].tagName!="HTML")A.instance.overflowYstart=A.instance.overflowY[0].scrollTop;if(A.instance.overflowX[0]!=document&&A.instance.overflowX[0].tagName!="HTML")A.instance.overflowXstart=A.instance.overflowX[0].scrollLeft},sort:function(C,B){var _=B.options,A=B.instance;if(A.overflowY[0]!=document&&A.overflowY[0].tagName!="HTML"){if(A.overflowY[0].offsetHeight-(B.position.top-A.overflowY[0].scrollTop+A.clickOffset.top)<_.scrollSensitivity)A.overflowY[0].scrollTop=A.overflowY[0].scrollTop+_.scrollSpeed;if((B.position.top-A.overflowY[0].scrollTop+A.clickOffset.top)<_.scrollSensitivity)A.overflowY[0].scrollTop=A.overflowY[0].scrollTop-_.scrollSpeed}else{if(C.pageY-$(document).scrollTop()<_.scrollSensitivity)$(document).scrollTop($(document).scrollTop()-_.scrollSpeed);if($(window).height()-(C.pageY-$(document).scrollTop())<_.scrollSensitivity)$(document).scrollTop($(document).scrollTop()+_.scrollSpeed)}if(A.overflowX[0]!=document&&A.overflowX[0].tagName!="HTML"){if(A.overflowX[0].offsetWidth-(B.position.left-A.overflowX[0].scrollLeft+A.clickOffset.left)<_.scrollSensitivity)A.overflowX[0].scrollLeft=A.overflowX[0].scrollLeft+_.scrollSpeed;if((B.position.top-A.overflowX[0].scrollLeft+A.clickOffset.left)<_.scrollSensitivity)A.overflowX[0].scrollLeft=A.overflowX[0].scrollLeft-_.scrollSpeed}else{if(C.pageX-$(document).scrollLeft()<_.scrollSensitivity)$(document).scrollLeft($(document).scrollLeft()-_.scrollSpeed);if($(window).width()-(C.pageX-$(document).scrollLeft())<_.scrollSensitivity)$(document).scrollLeft($(document).scrollLeft()+_.scrollSpeed)}A.offset={left:A.mouse.start.left-A.originalPosition.left+(A.overflowXstart!==undefined?A.overflowXstart-A.overflowX[0].scrollLeft:0),top:A.mouse.start.top-A.originalPosition.top+(A.overflowYstart!==undefined?A.overflowYstart-A.overflowX[0].scrollTop:0)}}})})(jQuery)