/*
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
Code licensed under the BSD License:
http://developer.yahoo.com/yui/license.html
version: 3.1.1
build: 47
*/
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(P){if(!P.drop.get(B).test(this.get(G))){return;}if(P.drag.get(B)==P.drop.get(B)){return;}switch(this.get("moveType").toLowerCase()){case"insert":var L=((this._up)?"before":"after");P.drop.get(B).insert(P.drag.get(B),L);break;case"swap":A.DD.DDM.swapNode(P.drag,P.drop);break;case"move":case"copy":var N=A.Sortable.getSortable(P.drop.get(B).get(H)),O,M;if(!N){return;}A.DD.DDM.getDrop(P.drag.get(B)).addToGroup(N.get(E));if(P.drag.get(B).get(H).contains(P.drop.get(B))){A.DD.DDM.swapNode(P.drag,P.drop);}else{if(this.get("moveType")=="copy"){O=P.drag.get(B);M=O.cloneNode(true);M.set(E,"");P.drag.set(B,M);N.delegate.createDrop(M,[N.get(E)]);O.setStyles({top:"",left:""});}P.drop.get(B).insert(P.drag.get(B),"before");}break;}},_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){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));}},{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:[],getSortable:function(M){var L=null;M=A.one(M);A.each(C._sortables,function(N){if(M.test(N.get(I))){L=N;}});return L;},reg:function(L){C._sortables.push(L);},unreg:function(L){A.each(C._sortables,function(N,M){if(N===L){C._sortables[M]=null;delete C._sortables[M];}});}});A.Sortable=C;},"3.1.1",{requires:["dd-delegate","dd-drop-plugin","dd-proxy"]});