Element.extend({getCis:function(){return this.getCoordinates()}});String.extend({format:function(){if(arguments.length==0){return this}var d=/{(\d+)?}/g;var c=arguments;var b=this;var a=this.replace(d,function(f,e){return c[e.toInt()]||""});return a}});var Scroller=new Class({Implements:[Events,Options],options:{area:20,velocity:1,onChange:function(a,b){this.element.scrollTo(a,b)}},initialize:function(b,a){this.setOptions(a);this.element=$(b);this.listener=($type(this.element)!="element")?$(this.element.getDocument().body):this.element;this.timer=null;this.coord=this.getCoords.bind(this)},start:function(){this.listener.addEvent("mousemove",this.coord)},stop:function(){this.listener.removeEvent("mousemove",this.coord);this.timer=$clear(this.timer)},getCoords:function(a){this.page=(this.listener.get("tag")=="body")?a.client:a.page;if(!this.timer){this.timer=this.scroll.periodical(50,this)}},scroll:function(){var b=this.element.getSize(),a=this.element.getScroll(),e=this.element.getPosition(),d={x:0,y:0};for(var c in this.page){if(this.page[c]<(this.options.area+e[c])&&a[c]!=0){d[c]=(this.page[c]-this.options.area-e[c])*this.options.velocity}else{if(this.page[c]+this.options.area>(b[c]+e[c])&&b[c]+b[c]!=a[c]){d[c]=(this.page[c]-b[c]+this.options.area-e[c])*this.options.velocity}}}if(d.y||d.x){this.fireEvent("change",[a.x+d.x,a.y+d.y])}}});var DragDropPlus=new Class({Implements:[Options,Events],options:{ddScope:window,onInitDrags:$empty,onInitDrops:$empty,onEdit:$empty,onDelete:$empty},initialize:function(b,c,a){this.dragSelecterString=b;this.dropSelecterString=c;this.drags=$$(b);this.drops=$$(c);this.setOptions(a);if(this.options.ddScope){this.winScroll=new Scroller(this.options.ddScope,{velocity:1})}this.drag_operate_box=$("drag_operate_box");if(!this.drag_operate_box){return}this.drag_operate_box.store("lock",false);this.drag_handle_box=$E(".drag_handle_box",this.drag_operate_box);this.dobFx=this.drag_operate_box.effects({fps:50,duration:200,link:"cancel"});this.dragSign=$("drag_ghost_box").inject(document.body);this.initDOBBase(this.drops);this.initDrags(this.drags);this.initDrops(this.drops)},checkEmptyDropPanel:function(a){if(!a||!a.hasClass(this.dropSelecterString.substring(1,this.dropSelecterString.length))){return}if(!a.getElement(this.dragSelecterString)){if(!a.getElement(".empty_drop_box")){new Element("div",{"class":"empty_drop_box"}).setText("空板块区域").inject(a);if(this.dragmoveInstance){a.store("droppanel",true);this.dragmoveInstance.droppables.include(a)}}}else{if(a.getElement(".empty_drop_box")){a.getElement(".empty_drop_box").remove()}}},dragLeave:function(){},dargInject:function(a,c){var d=this.dragging;if(!d){return}var b="inside";if(!c.retrieve("droppanel")){b=d.getAllPrevious().contains(c)?"before":"after"}d.inject(c,b);this.checkEmptyDropPanel(a.retrieve("droped"));this.checkEmptyDropPanel(c);a.store("droped",c);this.dragSign.setStyles(d.getCis())},getDropables:function(){var b=this.dragging;var a=$A(this.drags).remove(b).concat(this.drops.filter(function(c){if($E(this.dragSelecterString,c)){c.store("droppanel",false);return false}else{c.store("droppanel",true);return true}}.bind(this)));return a},initDOBBase:function(e){var d=this.drag_operate_box;var b=this.drag_handle_box;var c=this;if(!e){return}var a=this.winScroll;$E(".dhb_edit",b).addEvent("click",function(f){f.stop();this.fireEvent("onEdit",[d.retrieve("drag")],this)}.bind(this));$E(".dhb_del",b).addEvent("click",function(f){f.stop();this.fireEvent("onDelete",[d.retrieve("drag")],this)}.bind(this));$E(".dhb_title",b).addEvents({mousedown:function(f){c.dragging=d.retrieve("drag");d.setStyle("left",d.getPosition().x+10);d.store("droped",c.dragging.getParent(c.dropSelecterString));d.store("lock",true);c.dragmoveInstance=new Drag.Move(d,{handle:this,droppables:c.getDropables.call(c),snap:0,onEnter:c.dargInject.bind(c),onStart:function(g){c.dragSign.setStyles($extend(c.dragging.getCis(),{visibility:"visible"}));if(a){a.start()}},onComplete:function(g){if(a){a.stop()}c.dobFx.start(c.dragging.getCis()).chain(function(){this.element.store("lock",false)})}});c.dragmoveInstance.start(f)},mouseup:function(f){c.dragmoveInstance.stop(f);c.dragmoveInstance.cancel(f);c.dragmoveInstance.detach();if(c.dragSign){c.dragSign.setStyle("visibility","hidden")}}})},initDrags:function(a){var c=this.drops;var b=this;a.each(function(e,d){b.fireEvent("onInitDrags",[e,a],this);e.addEvents({mouseenter:function(){var g=b.drag_operate_box;if(g.retrieve("lock")){return}$E(".dhb_title",g).setHTML(e.get("title")||"&nbsp;");g.setStyle("visibility","visible");g.store("drag",this);var f=e.getCis();f=$merge(f,{height:f.height.limit(24,1000)});b.dobFx.start(f)}});$ES("a",e).removeEvents().addEvent("click",function(f){f.stop()});$ES("form",e).removeEvents().addEvent("submit",function(f){f.stop()})})},initDrops:function(b){var a=this;b.each(function(c,d){a.checkEmptyDropPanel(c);a.fireEvent("onInitDrops",[c,b],this)})}});