var a;if(typeof console=="undefined"){function console(){return 0}console.prototype={}}
function JFloatModules(b,c){c=c||{};this.containerClass=b;this.elementClass=c.element||"";this.handClass=c.hand||"h3";this.foldContentClass=c.fold||"";this.debug=c.debug||false;this.mod=c.mod||0;this.styles={};this.styles.hand=c.handClass||"";this.styles.element=c.elementClass||"";this.styles.onDrag=c.onDragClass||"";this.styles.onListOver=c.onListOverClass||"";this.styles.listOverlay=c.listOverlayClass||"";this.styles.firstInList=c.firstInListClass||"";this.styles.lastInList=c.lastInListClass||"";
this.styles.clone=c.cloneClass||"";this.styles.dragHand=c.dragHandClass||"";this.styles.foldHand=c.foldHandClass||"";this.doSaveState=c.doSaveState==null?true:c.doSaveState;this.useDragging=c.useDragging==null?true:c.useDragging;this.useFolding=c.useFolding==null?true:c.useFolding;this.mouse={x:0,y:0};this.stat={self:0,before:0,after:0,fake:0,loops:0};this.lists=[];this.clone=this.list=null;this.captureMouse=this.captureMouseHandle.bind(this);this.addLists($$(this.containerClass));if(this.debug){console.log(this.lists);
if(!$("pageX")){b=(new Element("div",{styles:{position:"fixed",left:"10px",top:"10px",width:"100px",opacity:"0.75",border:"1px solid black","background-color":"white"}})).inject(document.body);(new Element("span")).setText("pageX: ").inject(b);(new Element("span",{id:"pageX"})).setText("0").inject(b)}if(!$("pageY")){b=(new Element("div",{styles:{position:"fixed",left:"10px",top:"30px",width:"100px",opacity:"0.75",border:"1px solid black","background-color":"white"}})).inject(document.body);(new Element("span")).setText("pageY: ").inject(b);
(new Element("span",{id:"pageY"})).setText("0").inject(b)}$("debug")||(new Element("div",{id:"debug",styles:{position:"fixed",left:"10px",top:"50px",width:"100px",opacity:"0.75",border:"1px solid black","background-color":"white"}})).inject(document.body)}this.restoreState()}JFloatModules.prototype={};a=JFloatModules.prototype;
a.captureMouseHandle=function(b){b=new Event(b);this.mouse.x=b.page.x;this.mouse.y=b.page.y;if(this.debug){$("pageX").innerHTML=this.mouse.x;$("pageY").innerHTML=this.mouse.y}b=0;for(var c=this.lists.length;b<c;b++){var d=this.lists[b];if($type(this.list)!="element"&&this.isMouseOver(d)){this.listOver(d,b);break}else if($type(this.list)=="element"&&this.list==d&&!this.isMouseOver(d)){this.listLeave(d,b);break}}};
a.onListOver=function(){this.debug&&console.log("---\>onListOver<---");this.list.addClass(this.styles.onListOver);if($type(this.styles.listOverlay)=="string"&&this.styles.listOverlay!=""){this.list.$hover=(new Element("div")).addClass(this.styles.listOverlay).setStyles(this.list.getCoordinates()).setStyles({position:"absolute"}).setOpacity(0.3);this.list.$hover.inject(document.body)}};
a.onListLeave=function(b){this.debug&&console.log("---\>onListLeave<---");this.list.addClass(this.styles.onListOver);if($type(b.$hover)=="element"){b.$hover.remove();b.$hover=null}};a.isMouseOver=function(b,c){if(b.$cor==null)b.$cor=b.getCoordinates();return c==null?b.$cor.left<this.mouse.x&&this.mouse.x<b.$cor.right&&b.$cor.top<this.mouse.y&&this.mouse.y<b.$cor.bottom:c==true?b.$cor.left<this.mouse.x&&this.mouse.x<b.$cor.right:b.$cor.top<this.mouse.y&&this.mouse.y<b.$cor.bottom};
a.elementIsChild=function(b){return(!this.elementClass||b.hasClass(this.elementClass))&&b.getProperty("id")!="fmTrash"};
a.addItems=function(b){b=$A(b);for(var c=0;c<b.length;c++){var d=b[c],f=$E(this.handClass,d);if(f){d._h=f;if(this.useDragging){d._h.addClass(this.styles.hand).addEvent("mousedown",this.start.bindWithEvent(this,d));window.ie&&d._h.addEvents({mouseover:function(){this.addClass("hover")},mouseleave:function(){this.removeClass("hover")}})}d.$uid=f.getText().clean().replace(/\s/g,"_");d.addClass(this.styles.element);this.recalcPositions(d);if(this.useFolding==true){d._f=(new Element("div",{"class":this.styles.foldHand})).addEvents({mousedown:function(i){i=
(new Event(i)).stop()},click:this.blockFolding.bindWithEvent(this,d)}).injectBefore(d._h);f=d._h.getParent().getChildren();d._b=null;if(this.foldContentClass)d._b=$E(this.foldContentClass,d);if(!d._b){d._b=new Element("div");for(var g=false,e=0,h=f.length;e<h;e++)if(f[e]==d._h)g=true;else g==true&&$(f[e]).inject(d._b);d._b.injectAfter(d._h)}this.debug&&console.log("Defined content element: ",d._b);d._b.setStyles({overflow:"hidden"});d.$hidden=false}if(this.useDragging&&this.styles.dragHand){d._d=
(new Element("div",{"class":this.styles.dragHand})).addEvent("mousedown",this.start.bindWithEvent(this,d)).injectBefore(d._h);this.debug&&console.log("Dragging Handler: ",d._d)}if(this.debug){d.setStyle("border","1px solid blue");if(this.useDragging==true){d._h.setStyle("border","1px solid red");d._d.setStyle("border","1px solid lime")}if(this.useFolding==true){d._f.setStyle("border","1px solid pink");d._b.setStyle("border","1px solid violet")}}}}return this};
a.blockFolding=function(b,c){c.hasClass("hidden")?this.show(c):this.hide(c)};a.show=function(b){b.removeClass("hidden");(new Fx.Style(b._b,"height",{onComplete:function(){this.toggleStatus(b);b._b.setStyle("height","auto")}.bind(this)})).start(b._b.offsetHeight,b._b.scrollHeight)};a.hide=function(b){b.addClass("hidden");(new Fx.Style(b._b,"height",{onComplete:this.toggleStatus.bind(this,b)})).start(b._b.offsetHeight,0)};
a.toggleStatus=function(b){b.$hidden=b.$hidden?false:true;this.debug&&console.log("--\>Status Changed:",b,b.$hidden);this.storeState()};a.getListChildren=function(b){if(!b)b=this.list;var c=[];b=$$(b.getChildren());for(var d=0;d<b.length;d++)this.elementIsChild(b[d])&&c.push(b[d]);return c};
a.recalcListCoor=function(b){this.debug&&console.log("--\>RecalcList",b);b.$elements=this.getListChildren(b);b.$cor=b.getCoordinates();b.$hover&&b.$hover.setStyles(b.$cor);b.$cor.left-=this.mod;b.$cor.top-=this.mod;b.$cor.right+=this.mod;b.$cor.bottom+=this.mod;return this};a.recalcListsCoor=function(){this.debug&&console.log("--\>RecalcListsCoor",this.lists);for(var b=0;b<this.lists.length;b++)this.recalcListCoor(this.lists[b]);return this};
a.addLists=function(b){for(var c=0;c<b.length;c++){this.debug&&b[c].setStyle("border","1px solid lime");b[c].$uid=this.lists.length;b[c].$elements=this.getListChildren(b[c]);this.lists.push(b[c]);this.addItems(b[c].$elements)}this.recalcListsCoor()};a.listOver=function(b){this.debug&&console.log("--\>Mouse over list:",b,"adding");this.list=b;this.recalcPositions();this.onListOver(b)};
a.listLeave=function(b){this.debug&&console.log("--\>Mouse out list:",b,"removing");this.onListLeave(b);this.list=null};
a.start=function(b,c){if(this.debug){console.log("JFloatModules.start");this.stat={self:0,before:0,after:0,fake:0,loops:0}}this.element=c;this.getClone(c);this.list=c.getParent();document.addEvent("mousemove",this.captureMouse);this.drag=new Drag.Move(this.clone,{snap:4,droppables:this.lists,onComplete:this.end.bind(this),onDrag:this.move.bind(this),onStart:function(){this.debug&&console.log("---\>Start<---",b);this.element.addClass(this.styles.onDrag);this.onListOver();b.stop();this.clone.setStyle("visibility",
"visible")}.bind(this)});this.drag.start(b)};a.recalcPositions=function(){this.debug&&console.log("--\>Recalc position");var b=$A(arguments.length>0?arguments:this.list.$elements);this.debug&&console.log(b);if(b)for(var c=0;c<b.length;c++){var d=b[c];if(d!=null)if($type(d)=="element"){d.$cor=d.getCoordinates();d.$cor.middle=d.$cor.top+parseInt((d.$cor.bottom-d.$cor.top)/2);d.$prev=d.getPrevious();d.$next=d.getNext()}}else this.debug&&console.log("--\>Recalc position--\>List is empty");return this};
a.move=function(){if(this.list)if(this.list.$elements.length==0){this.debug&&$("debug").setText("Empty");this.element.inject(this.list);this.recalcListsCoor().recalcPositions()}else for(var b=0;b<this.list.$elements.length;b++){var c=this.list.$elements[b];this.stat.loops++;if(c.$uid==this.element.$uid)this.stat.self++;else if(this.isMouseOver(c,false)){if(this.mouse.y<c.$cor.middle){if(c.$prev==null||c.$prev.$uid!=this.element.$uid){this.debug&&$("debug").setText("before");this.element.injectBefore(c);
this.recalcListsCoor().recalcPositions(c,c.$next,c.$prev);this.stat.before++;continue}}else if(c.$next==null||c.$next.$uid!=this.element.$uid){this.debug&&$("debug").setText("after");this.element.injectAfter(c);this.recalcListsCoor().recalcPositions(c,c.$next,c.$prev);this.stat.after++;continue}this.stat.fake++}}};
a.end=function(){this.debug&&console.log("---\>Complete<---");this.drag.detach();this.element.removeClass(this.styles.onDrag);this.reset().markElements().storeState();document.removeEvent("mousemove",this.captureMouse)};
a.markElements=function(){this.debug&&console.log("--\>markElements");this.list&&this.onListLeave(this.list);for(var b=0;b<this.lists.length;b++){var c=this.lists[b];c.$elements=$A(c.$elements);for(var d=0;d<c.$elements.length;d++){this.styles.firstInList!=""&&c.$elements[d].removeClass(this.styles.firstInList);this.styles.lastInList!=""&&c.$elements[d].removeClass(this.styles.lastInList)}this.styles.firstInList!=""&&c.$elements.length>0&&c.$elements[0].addClass(this.styles.firstInList);this.styles.lastInList!=
""&&c.$elements.length>2&&c.$elements[c.$elements.length-1].addClass(this.styles.lastInList)}return this};a.reset=function(){this.clone.remove();return this};a.getClone=function(b){this.clone=(new Element("div",{id:"fmTrash"})).setStyles({backgroundColor:"white",margin:"0px",position:"absolute",visibility:"hidden",zIndex:"15"}).setOpacity(0.7).addClass(this.styles.clone).setStyles(b.getCoordinates()).inject(b.getParent());b.clone().inject(this.clone);return this};
a.storeState=function(){if(this.doSaveState!=true)return this;for(var b=[],c={},d=0,f=this.lists.length;d<f;d++){b[this.lists[d].$uid]=[];for(var g=this.getListChildren(this.lists[d]),e=0,h=g.length;e<h;e++){b[this.lists[d].$uid].unshift(g[e].$uid);c[g[e].$uid]=g[e].$hidden}}Cookie.set(this.getCookieName(),Json.toString(b),{duration:365});Cookie.set(this.getCookieName("folding"),Json.toString(c),{duration:365});this.debug&&console.log("state:",b)};
a.restoreState=function(){if(this.doSaveState!=true)return this;var b=Json.evaluate(Cookie.get(this.getCookieName())),c=Json.evaluate(Cookie.get(this.getCookieName("folding")));if(this.debug){console.log("State from cookie:",b);console.log("Folding from cookie:",c)}if($type(b)=="array"){for(var d=0;d<b.length;d++){var f=b[d];this.debug&&console.log("Restore Ordering for list: ",d,f);for(var g=0;g<f.length;g++){var e=f[g],h=this.getElementByUID(e);if(h){this.debug&&console.log(h);if(this.lists[d]){var i=
this.lists[d].getFirst();if(i!=null){if(i.$uid!=h.$uid){this.debug&&console.log("Element:",e,"in",d,h,"in",this.lists[d]);h.injectBefore(this.lists[d].getFirst())}}else h.inject(this.lists[d])}}}}this.recalcListsCoor();this.markElements()}if($type(c)=="object")for(e in c){b=c[e];if(b==true)if(h=this.getElementByUID(e)){h.$hidden=b;h.addClass("hidden");h._b.setStyle("height",0)}}return this};
a.getCookieName=function(b){return("floatModules.state."+this.containerClass+(b?"."+b:"")).replace("state..","state.")};a.getElementByUID=function(b){for(var c=0,d=this.lists.length;c<d;c++)for(var f=this.getListChildren(this.lists[c]),g=0,e=f.length;g<e;g++)if(f[g].$uid==b)return f[g]};