/*
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.com/yui/license.html
version: 3.2.0
build: 2676
*/
YUI.add("sortable",function(A){var C=function(L){C.superclass.constructor.apply(this,arguments);},F="currentNode",D="opacityNode",I="container",E="id",J="zIndex",K="opacity",H="parentNode",G="nodes",B="node";A.extend(C,A.Base,{delegate:null,initializer:function(){var O="sortable-"+A.guid(),N,M={container:this.get(I),nodes:this.get(G),target:true,invalid:this.get("invalid"),dragConfig:{groups:[O]}},L;if(this.get("handles")){M.handles=this.get("handles");}L=new A.DD.Delegate(M);this.set(E,O);L.dd.plug(A.Plugin.DDProxy,{moveOnEnd:false,cloneNode:true});N=new A.DD.Drop({node:this.get(I),bubbleTarget:L,groups:L.dd.get("groups")}).on("drop:over",A.bind(this._onDropOver,this));L.on({"drag:start":A.bind(this._onDragStart,this),"drag:end":A.bind(this._onDragEnd,this),"drag:over":A.bind(this._onDragOver,this),"drag:drag":A.bind(this._onDrag,this)});this.delegate=L;C.reg(this);},_up:null,_y:null,_onDrag:function(L){if(L.pageY<this._y){this._up=true;}else{if(L.pageY>this._y){this._up=false;}}this._y=L.pageY;},_onDropOver:function(M){if(!M.drop.get(B).test(this.get(G))){var L=M.drop.get(B).all(this.get(G));if(L.size()===0){M.drop.get(B).append(M.drag.get(B));}}},_onDragOver:function(R){if(!R.drop.get(B).test(this.get(G))){return;}if(R.drag.get(B)==R.drop.get(B)){return;}if(R.drag.get(B).contains(R.drop.get(B))){return;}var S=false,M,Q,O,N,L,P=this.get("moveType").toLowerCase();if(R.drag.get(B).get(H).contains(R.drop.get(B))){S=true;}if(S&&P=="move"){P="insert";}switch(P){case"insert":M=((this._up)?"before":"after");L=R.drop.get(B);if(A.Sortable._test(L,this.get(I))){L.append(R.drag.get(B));}else{L.insert(R.drag.get(B),M);}break;case"swap":A.DD.DDM.swapNode(R.drag,R.drop);break;case"move":case"copy":N=A.Sortable.getSortable(R.drop.get(B).get(H));if(!N){return;}A.DD.DDM.getDrop(R.drag.get(B)).addToGroup(N.get(E));if(S){A.DD.DDM.swapNode(R.drag,R.drop);}else{if(this.get("moveType")=="copy"){Q=R.drag.get(B);O=Q.cloneNode(true);O.set(E,"");R.drag.set(B,O);N.delegate.createDrop(O,[N.get(E)]);Q.setStyles({top:"",left:""});}R.drop.get(B).insert(R.drag.get(B),"before");}break;}this.fire(P,{same:S,drag:R.drag,drop:R.drop});this.fire("moved",{same:S,drag:R.drag,drop:R.drop});},_onDragStart:function(L){this.delegate.get("lastNode").setStyle(J,"");this.delegate.get(this.get(D)).setStyle(K,this.get(K));this.delegate.get(F).setStyle(J,"999");},_onDragEnd:function(L){this.delegate.get(this.get(D)).setStyle(K,1);this.delegate.get(F).setStyles({top:"",left:""});this.sync();},plug:function(L,M){if(L&&L.NAME.substring(0,4).toLowerCase()==="sort"){this.constructor.superclass.plug.call(this,L,M);}else{this.delegate.dd.plug(L,M);}return this;},sync:function(){this.delegate.syncTargets();return this;},destructor:function(){this.delegate.destroy();C.unreg(this);},join:function(M,L){if(!(M instanceof A.Sortable)){A.error("Sortable: join needs a Sortable Instance");return this;}if(!L){L="full";}L=L.toLowerCase();var N="_join_"+L;if(this[N]){this[N](M);}return this;},_join_none:function(L){this.delegate.dd.removeFromGroup(L.get(E));L.delegate.dd.removeFromGroup(this.get(E));},_join_full:function(L){this.delegate.dd.addToGroup(L.get(E));L.delegate.dd.addToGroup(this.get(E));},_join_outer:function(L){this.delegate.dd.addToGroup(L.get(E));},_join_inner:function(L){L.delegate.dd.addToGroup(this.get(E));},getOrdering:function(M){var L=[];if(!A.Lang.isFunction(M)){M=function(N){return N;};}A.one(this.get(I)).all(this.get(G)).each(function(N){L.push(M(N));});return L;}},{NAME:"sortable",ATTRS:{handles:{value:false},container:{value:"body"},nodes:{value:".dd-draggable"},opacity:{value:".75"},opacityNode:{value:"currentNode"},id:{value:null},moveType:{value:"insert"},invalid:{value:""}},_sortables:[],_test:function(L,M){if(M instanceof A.Node){return(M===L);}else{return L.test(M);}},getSortable:function(M){var L=null;M=A.one(M);A.each(A.Sortable._sortables,function(N){if(A.Sortable._test(M,N.get(I))){L=N;}});return L;},reg:function(L){A.Sortable._sortables.push(L);},unreg:function(L){A.each(A.Sortable._sortables,function(N,M){if(N===L){A.Sortable._sortables[M]=null;delete C._sortables[M];}});}});A.Sortable=C;},"3.2.0",{requires:["dd-delegate","dd-drop-plugin","dd-proxy"]});