Index: ruby/trunk/public/javascripts/dragdrop.js
===================================================================
--- ruby/trunk/public/javascripts/dragdrop.js	(revision 291)
+++ ruby/trunk/public/javascripts/dragdrop.js	(revision 372)
@@ -1,5 +1,5 @@
 // Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
-//           (c) 2005-2007 Sammi Williams (http://www.oriontransfer.co.nz, sammi@oriontransfer.co.nz)
-// 
+//           (c) 2005-2008 Sammi Williams (http://www.oriontransfer.co.nz, sammi@oriontransfer.co.nz)
+//
 // script.aculo.us is freely distributable under the terms of an MIT-style license.
 // For details, see the script.aculo.us web site: http://script.aculo.us/
@@ -33,5 +33,5 @@
       }
     }
-    
+
     if(options.accept) options.accept = [options.accept].flatten();
 
@@ -41,12 +41,12 @@
     this.drops.push(options);
   },
-  
+
   findDeepestChild: function(drops) {
     deepest = drops[0];
-      
+
     for (i = 1; i < drops.length; ++i)
       if (Element.isParent(drops[i].element, deepest.element))
         deepest = drops[i];
-    
+
     return deepest;
   },
@@ -55,5 +55,5 @@
     var containmentNode;
     if(drop.tree) {
-      containmentNode = element.treeNode; 
+      containmentNode = element.treeNode;
     } else {
       containmentNode = element.parentNode;
@@ -61,5 +61,5 @@
     return drop._containers.detect(function(c) { return containmentNode == c });
   },
-  
+
   isAffected: function(point, element, drop) {
     return (
@@ -68,5 +68,5 @@
         this.isContained(element, drop)) &&
       ((!drop.accept) ||
-        (Element.classNames(element).detect( 
+        (Element.classNames(element).detect(
           function(v) { return drop.accept.include(v) } ) )) &&
       Position.within(drop.element, point[0], point[1]) );
@@ -88,10 +88,10 @@
     if(!this.drops.length) return;
     var drop, affected = [];
-    
+
     this.drops.each( function(drop) {
       if(Droppables.isAffected(point, element, drop))
         affected.push(drop);
     });
-        
+
     if(affected.length>0)
       drop = Droppables.findDeepestChild(affected);
@@ -102,5 +102,5 @@
       if(drop.onHover)
         drop.onHover(element, drop.element, Position.overlap(drop.overlap, drop.element));
-      
+
       if (drop != this.last_active) Droppables.activate(drop);
     }
@@ -113,6 +113,6 @@
     if (this.isAffected([Event.pointerX(event), Event.pointerY(event)], element, this.last_active))
       if (this.last_active.onDrop) {
-        this.last_active.onDrop(element, this.last_active.element, event); 
-        return true; 
+        this.last_active.onDrop(element, this.last_active.element, event);
+        return true;
       }
   },
@@ -122,10 +122,10 @@
       this.deactivate(this.last_active);
   }
-}
+};
 
 var Draggables = {
   drags: [],
   observers: [],
-  
+
   register: function(draggable) {
     if(this.drags.length == 0) {
@@ -133,5 +133,5 @@
       this.eventMouseMove = this.updateDrag.bindAsEventListener(this);
       this.eventKeypress  = this.keyPress.bindAsEventListener(this);
-      
+
       Event.observe(document, "mouseup", this.eventMouseUp);
       Event.observe(document, "mousemove", this.eventMouseMove);
@@ -140,5 +140,5 @@
     this.drags.push(draggable);
   },
-  
+
   unregister: function(draggable) {
     this.drags = this.drags.reject(function(d) { return d==draggable });
@@ -149,12 +149,12 @@
     }
   },
-  
+
   activate: function(draggable) {
-    if(draggable.options.delay) { 
-      this._timeout = setTimeout(function() { 
-        Draggables._timeout = null; 
-        window.focus(); 
-        Draggables.activeDraggable = draggable; 
-      }.bind(this), draggable.options.delay); 
+    if(draggable.options.delay) {
+      this._timeout = setTimeout(function() {
+        Draggables._timeout = null;
+        window.focus();
+        Draggables.activeDraggable = draggable;
+      }.bind(this), draggable.options.delay);
     } else {
       window.focus(); // allows keypress events if window isn't currently focused, fails for Safari
@@ -162,9 +162,9 @@
     }
   },
-  
+
   deactivate: function() {
     this.activeDraggable = null;
   },
-  
+
   updateDrag: function(event) {
     if(!this.activeDraggable) return;
@@ -174,12 +174,12 @@
     if(this._lastPointer && (this._lastPointer.inspect() == pointer.inspect())) return;
     this._lastPointer = pointer;
-    
+
     this.activeDraggable.updateDrag(event, pointer);
   },
-  
+
   endDrag: function(event) {
-    if(this._timeout) { 
-      clearTimeout(this._timeout); 
-      this._timeout = null; 
+    if(this._timeout) {
+      clearTimeout(this._timeout);
+      this._timeout = null;
     }
     if(!this.activeDraggable) return;
@@ -188,20 +188,20 @@
     this.activeDraggable = null;
   },
-  
+
   keyPress: function(event) {
     if(this.activeDraggable)
       this.activeDraggable.keyPress(event);
   },
-  
+
   addObserver: function(observer) {
     this.observers.push(observer);
     this._cacheObserverCallbacks();
   },
-  
+
   removeObserver: function(element) {  // element instead of observer fixes mem leaks
     this.observers = this.observers.reject( function(o) { return o.element==element });
     this._cacheObserverCallbacks();
   },
-  
+
   notify: function(eventName, draggable, event) {  // 'onStart', 'onEnd', 'onDrag'
     if(this[eventName+'Count'] > 0)
@@ -211,5 +211,5 @@
     if(draggable.options[eventName]) draggable.options[eventName](draggable, event);
   },
-  
+
   _cacheObserverCallbacks: function() {
     ['onStart','onEnd','onDrag'].each( function(eventName) {
@@ -219,5 +219,5 @@
     });
   }
-}
+};
 
 /*--------------------------------------------------------------------------*/
@@ -235,10 +235,10 @@
       endeffect: function(element) {
         var toOpacity = Object.isNumber(element._opacity) ? element._opacity : 1.0;
-        new Effect.Opacity(element, {duration:0.2, from:0.7, to:toOpacity, 
+        new Effect.Opacity(element, {duration:0.2, from:0.7, to:toOpacity,
           queue: {scope:'_draggable', position:'end'},
-          afterFinish: function(){ 
-            Draggable._dragging[element] = false 
+          afterFinish: function(){
+            Draggable._dragging[element] = false
           }
-        }); 
+        });
       },
       zindex: 1000,
@@ -251,5 +251,5 @@
       delay: 0
     };
-    
+
     if(!arguments[1] || Object.isUndefined(arguments[1].endeffect))
       Object.extend(defaults, {
@@ -257,18 +257,18 @@
           element._opacity = Element.getOpacity(element);
           Draggable._dragging[element] = true;
-          new Effect.Opacity(element, {duration:0.2, from:element._opacity, to:0.7}); 
+          new Effect.Opacity(element, {duration:0.2, from:element._opacity, to:0.7});
         }
       });
-    
+
     var options = Object.extend(defaults, arguments[1] || { });
 
     this.element = $(element);
-    
+
     if(options.handle && Object.isString(options.handle))
       this.handle = this.element.down('.'+options.handle, 0);
-    
+
     if(!this.handle) this.handle = $(options.handle);
     if(!this.handle) this.handle = this.element;
-    
+
     if(options.scroll && !options.scroll.scrollTo && !options.scroll.outerHTML) {
       options.scroll = $(options.scroll);
@@ -276,20 +276,20 @@
     }
 
-    Element.makePositioned(this.element); // fix IE    
+    Element.makePositioned(this.element); // fix IE
 
     this.options  = options;
-    this.dragging = false;   
+    this.dragging = false;
 
     this.eventMouseDown = this.initDrag.bindAsEventListener(this);
     Event.observe(this.handle, "mousedown", this.eventMouseDown);
-    
+
     Draggables.register(this);
   },
-  
+
   destroy: function() {
     Event.stopObserving(this.handle, "mousedown", this.eventMouseDown);
     Draggables.unregister(this);
   },
-  
+
   currentDelta: function() {
     return([
@@ -297,9 +297,9 @@
       parseInt(Element.getStyle(this.element,'top') || '0')]);
   },
-  
+
   initDrag: function(event) {
     if(!Object.isUndefined(Draggable._dragging[this.element]) &&
       Draggable._dragging[this.element]) return;
-    if(Event.isLeftClick(event)) {    
+    if(Event.isLeftClick(event)) {
       // abort on form elements, fixes a Firefox issue
       var src = Event.element(event);
@@ -310,32 +310,32 @@
         tag_name=='BUTTON' ||
         tag_name=='TEXTAREA')) return;
-        
+
       var pointer = [Event.pointerX(event), Event.pointerY(event)];
       var pos     = Position.cumulativeOffset(this.element);
       this.offset = [0,1].map( function(i) { return (pointer[i] - pos[i]) });
-      
+
       Draggables.activate(this);
       Event.stop(event);
     }
   },
-  
+
   startDrag: function(event) {
     this.dragging = true;
     if(!this.delta)
       this.delta = this.currentDelta();
-    
+
     if(this.options.zindex) {
       this.originalZ = parseInt(Element.getStyle(this.element,'z-index') || 0);
       this.element.style.zIndex = this.options.zindex;
     }
-    
+
     if(this.options.ghosting) {
       this._clone = this.element.cloneNode(true);
-      this.element._originallyAbsolute = (this.element.getStyle('position') == 'absolute');
-      if (!this.element._originallyAbsolute)
+      this._originallyAbsolute = (this.element.getStyle('position') == 'absolute');
+      if (!this._originallyAbsolute)
         Position.absolutize(this.element);
       this.element.parentNode.insertBefore(this._clone, this.element);
     }
-    
+
     if(this.options.scroll) {
       if (this.options.scroll == window) {
@@ -348,26 +348,26 @@
       }
     }
-    
+
     Draggables.notify('onStart', this, event);
-        
+
     if(this.options.starteffect) this.options.starteffect(this.element);
   },
-  
+
   updateDrag: function(event, pointer) {
     if(!this.dragging) this.startDrag(event);
-    
+
     if(!this.options.quiet){
       Position.prepare();
       Droppables.show(pointer, this.element);
     }
-    
+
     Draggables.notify('onDrag', this, event);
-    
+
     this.draw(pointer);
     if(this.options.change) this.options.change(this);
-    
+
     if(this.options.scroll) {
       this.stopScrolling();
-      
+
       var p;
       if (this.options.scroll == window) {
@@ -387,14 +387,14 @@
       this.startScrolling(speed);
     }
-    
+
     // fix AppleWebKit rendering
     if(Prototype.Browser.WebKit) window.scrollBy(0,0);
-    
+
     Event.stop(event);
   },
-  
+
   finishDrag: function(event, success) {
     this.dragging = false;
-    
+
     if(this.options.quiet){
       Position.prepare();
@@ -404,15 +404,15 @@
 
     if(this.options.ghosting) {
-      if (!this.element._originallyAbsolute)
+      if (!this._originallyAbsolute)
         Position.relativize(this.element);
-      delete this.element._originallyAbsolute;
+      delete this._originallyAbsolute;
       Element.remove(this._clone);
       this._clone = null;
     }
 
-    var dropped = false; 
-    if(success) { 
-      dropped = Droppables.fire(event, this.element); 
-      if (!dropped) dropped = false; 
+    var dropped = false;
+    if(success) {
+      dropped = Droppables.fire(event, this.element);
+      if (!dropped) dropped = false;
     }
     if(dropped && this.options.onDropped) this.options.onDropped(this.element);
@@ -421,5 +421,5 @@
     var revert = this.options.revert;
     if(revert && Object.isFunction(revert)) revert = revert(this.element);
-    
+
     var d = this.currentDelta();
     if(revert && this.options.reverteffect) {
@@ -434,11 +434,11 @@
       this.element.style.zIndex = this.originalZ;
 
-    if(this.options.endeffect) 
+    if(this.options.endeffect)
       this.options.endeffect(this.element);
-      
+
     Draggables.deactivate(this);
     Droppables.reset();
   },
-  
+
   keyPress: function(event) {
     if(event.keyCode!=Event.KEY_ESC) return;
@@ -446,5 +446,5 @@
     Event.stop(event);
   },
-  
+
   endDrag: function(event) {
     if(!this.dragging) return;
@@ -453,5 +453,5 @@
     Event.stop(event);
   },
-  
+
   draw: function(point) {
     var pos = Position.cumulativeOffset(this.element);
@@ -460,17 +460,17 @@
       pos[0] += r[0] - Position.deltaX; pos[1] += r[1] - Position.deltaY;
     }
-    
+
     var d = this.currentDelta();
     pos[0] -= d[0]; pos[1] -= d[1];
-    
+
     if(this.options.scroll && (this.options.scroll != window && this._isScrollChild)) {
       pos[0] -= this.options.scroll.scrollLeft-this.originalScrollLeft;
       pos[1] -= this.options.scroll.scrollTop-this.originalScrollTop;
     }
-    
-    var p = [0,1].map(function(i){ 
-      return (point[i]-pos[i]-this.offset[i]) 
+
+    var p = [0,1].map(function(i){
+      return (point[i]-pos[i]-this.offset[i])
     }.bind(this));
-    
+
     if(this.options.snap) {
       if(Object.isFunction(this.options.snap)) {
@@ -479,11 +479,11 @@
       if(Object.isArray(this.options.snap)) {
         p = p.map( function(v, i) {
-          return (v/this.options.snap[i]).round()*this.options.snap[i] }.bind(this))
+          return (v/this.options.snap[i]).round()*this.options.snap[i] }.bind(this));
       } else {
         p = p.map( function(v) {
-          return (v/this.options.snap).round()*this.options.snap }.bind(this))
+          return (v/this.options.snap).round()*this.options.snap }.bind(this));
       }
     }}
-    
+
     var style = this.element.style;
     if((!this.options.constraint) || (this.options.constraint=='horizontal'))
@@ -491,8 +491,8 @@
     if((!this.options.constraint) || (this.options.constraint=='vertical'))
       style.top  = p[1] + "px";
-    
+
     if(style.visibility=="hidden") style.visibility = ""; // fix gecko rendering
   },
-  
+
   stopScrolling: function() {
     if(this.scrollInterval) {
@@ -502,5 +502,5 @@
     }
   },
-  
+
   startScrolling: function(speed) {
     if(!(speed[0] || speed[1])) return;
@@ -509,5 +509,5 @@
     this.scrollInterval = setInterval(this.scroll.bind(this), 10);
   },
-  
+
   scroll: function() {
     var current = new Date();
@@ -525,5 +525,5 @@
       this.options.scroll.scrollTop  += this.scrollSpeed[1] * delta / 1000;
     }
-    
+
     Position.prepare();
     Droppables.show(Draggables._lastPointer, this.element);
@@ -539,8 +539,8 @@
       this.draw(Draggables._lastScrollPointer);
     }
-    
+
     if(this.options.change) this.options.change(this);
   },
-  
+
   _getWindowScroll: function(w) {
     var T, L, W, H;
@@ -561,5 +561,5 @@
       } else {
         W = body.offsetWidth;
-        H = body.offsetHeight
+        H = body.offsetHeight;
       }
     }
@@ -578,9 +578,9 @@
     this.lastValue = Sortable.serialize(this.element);
   },
-  
+
   onStart: function() {
     this.lastValue = Sortable.serialize(this.element);
   },
-  
+
   onEnd: function() {
     Sortable.unmark();
@@ -592,9 +592,9 @@
 var Sortable = {
   SERIALIZE_RULE: /^[^_\-](?:[A-Za-z0-9\-\_]*)[_](.*)$/,
-  
+
   sortables: { },
-  
+
   _findRootElement: function(element) {
-    while (element.tagName.toUpperCase() != "BODY") {  
+    while (element.tagName.toUpperCase() != "BODY") {
       if(element.id && Sortable.sortables[element.id]) return element;
       element = element.parentNode;
@@ -607,13 +607,14 @@
     return Sortable.sortables[element.id];
   },
-  
+
   destroy: function(element){
-    var s = Sortable.options(element);
-    
+    element = $(element);
+    var s = Sortable.sortables[element.id];
+
     if(s) {
       Draggables.removeObserver(s.element);
       s.droppables.each(function(d){ Droppables.remove(d) });
       s.draggables.invoke('destroy');
-      
+
       delete Sortable.sortables[s.element.id];
     }
@@ -622,5 +623,5 @@
   create: function(element) {
     element = $(element);
-    var options = Object.extend({ 
+    var options = Object.extend({
       element:     element,
       tag:         'li',       // assumes li children, override with tag: 'tagname'
@@ -636,15 +637,15 @@
       hoverclass:  null,
       ghosting:    false,
-      quiet:       false, 
+      quiet:       false,
       scroll:      false,
       scrollSensitivity: 20,
       scrollSpeed: 15,
       format:      this.SERIALIZE_RULE,
-      
-      // these take arrays of elements or ids and can be 
+
+      // these take arrays of elements or ids and can be
       // used for better initialization performance
       elements:    false,
       handles:     false,
-      
+
       onChange:    Prototype.emptyFunction,
       onUpdate:    Prototype.emptyFunction
@@ -683,5 +684,5 @@
       options_for_draggable.zindex = options.zindex;
 
-    // build options for the droppables  
+    // build options for the droppables
     var options_for_droppable = {
       overlap:     options.overlap,
@@ -690,6 +691,6 @@
       hoverclass:  options.hoverclass,
       onHover:     Sortable.onHover
-    }
-    
+    };
+
     var options_for_tree = {
       onHover:      Sortable.onEmptyHover,
@@ -697,8 +698,8 @@
       containment:  options.containment,
       hoverclass:   options.hoverclass
-    }
+    };
 
     // fix for gecko engine
-    Element.cleanWhitespace(element); 
+    Element.cleanWhitespace(element);
 
     options.draggables = [];
@@ -713,12 +714,12 @@
     (options.elements || this.findElements(element, options) || []).each( function(e,i) {
       var handle = options.handles ? $(options.handles[i]) :
-        (options.handle ? $(e).select('.' + options.handle)[0] : e); 
+        (options.handle ? $(e).select('.' + options.handle)[0] : e);
       options.draggables.push(
         new Draggable(e, Object.extend(options_for_draggable, { handle: handle })));
       Droppables.add(e, options_for_droppable);
       if(options.tree) e.treeNode = element;
-      options.droppables.push(e);      
+      options.droppables.push(e);
     });
-    
+
     if(options.tree) {
       (Sortable.findTreeElements(element, options) || []).each( function(e) {
@@ -742,5 +743,5 @@
       element, options.only, options.tree ? true : false, options.tag);
   },
-  
+
   findTreeElements: function(element, options) {
     return Element.findChildren(
@@ -759,5 +760,5 @@
         element.style.visibility = "hidden"; // fix gecko rendering
         dropon.parentNode.insertBefore(element, dropon);
-        if(dropon.parentNode!=oldParentNode) 
+        if(dropon.parentNode!=oldParentNode)
           Sortable.options(oldParentNode).onChange(element);
         Sortable.options(dropon.parentNode).onChange(element);
@@ -770,5 +771,5 @@
         element.style.visibility = "hidden"; // fix gecko rendering
         dropon.parentNode.insertBefore(element, nextElement);
-        if(dropon.parentNode!=oldParentNode) 
+        if(dropon.parentNode!=oldParentNode)
           Sortable.options(oldParentNode).onChange(element);
         Sortable.options(dropon.parentNode).onChange(element);
@@ -776,18 +777,18 @@
     }
   },
-  
+
   onEmptyHover: function(element, dropon, overlap) {
     var oldParentNode = element.parentNode;
     var droponOptions = Sortable.options(dropon);
-        
+
     if(!Element.isParent(dropon, element)) {
       var index;
-      
+
       var children = Sortable.findElements(dropon, {tag: droponOptions.tag, only: droponOptions.only});
       var child = null;
-            
+
       if(children) {
         var offset = Element.offsetSize(dropon, droponOptions.overlap) * (1.0 - overlap);
-        
+
         for (index = 0; index < children.length; index += 1) {
           if (offset - Element.offsetSize (children[index], droponOptions.overlap) >= 0) {
@@ -802,7 +803,7 @@
         }
       }
-      
+
       dropon.insertBefore(element, child);
-      
+
       Sortable.options(oldParentNode).onChange(element);
       droponOptions.onChange(element);
@@ -817,32 +818,32 @@
     // mark on ghosting only
     var sortable = Sortable.options(dropon.parentNode);
-    if(sortable && !sortable.ghosting) return; 
+    if(sortable && !sortable.ghosting) return;
 
     if(!Sortable._marker) {
-      Sortable._marker = 
+      Sortable._marker =
         ($('dropmarker') || Element.extend(document.createElement('DIV'))).
           hide().addClassName('dropmarker').setStyle({position:'absolute'});
       document.getElementsByTagName("body").item(0).appendChild(Sortable._marker);
-    }    
+    }
     var offsets = Position.cumulativeOffset(dropon);
     Sortable._marker.setStyle({left: offsets[0]+'px', top: offsets[1] + 'px'});
-    
+
     if(position=='after')
-      if(sortable.overlap == 'horizontal') 
+      if(sortable.overlap == 'horizontal')
         Sortable._marker.setStyle({left: (offsets[0]+dropon.clientWidth) + 'px'});
       else
         Sortable._marker.setStyle({top: (offsets[1]+dropon.clientHeight) + 'px'});
-    
+
     Sortable._marker.show();
   },
-  
+
   _tree: function(element, options, parent) {
     var children = Sortable.findElements(element, options) || [];
-  
+
     for (var i = 0; i < children.length; ++i) {
       var match = children[i].id.match(options.format);
 
       if (!match) continue;
-      
+
       var child = {
         id: encodeURIComponent(match ? match[1] : null),
@@ -852,14 +853,14 @@
         position: parent.children.length,
         container: $(children[i]).down(options.treeTag)
-      }
-      
+      };
+
       /* Get the element containing the children and recurse over it */
       if (child.container)
-        this._tree(child.container, options, child)
-      
+        this._tree(child.container, options, child);
+
       parent.children.push (child);
     }
 
-    return parent; 
+    return parent;
   },
 
@@ -874,5 +875,5 @@
       format: sortableOptions.format
     }, arguments[1] || { });
-    
+
     var root = {
       id: null,
@@ -881,6 +882,6 @@
       container: element,
       position: 0
-    }
-    
+    };
+
     return Sortable._tree(element, options, root);
   },
@@ -898,5 +899,5 @@
     element = $(element);
     var options = Object.extend(this.options(element), arguments[1] || { });
-    
+
     return $(this.findElements(element, options) || []).map( function(item) {
       return item.id.match(options.format) ? item.id.match(options.format)[1] : '';
@@ -907,5 +908,5 @@
     element = $(element);
     var options = Object.extend(this.options(element), arguments[2] || { });
-    
+
     var nodeMap = { };
     this.findElements(element, options).each( function(n) {
@@ -914,5 +915,5 @@
         n.parentNode.removeChild(n);
     });
-   
+
     new_sequence.each(function(ident) {
       var n = nodeMap[ident];
@@ -923,5 +924,5 @@
     });
   },
-  
+
   serialize: function(element) {
     element = $(element);
@@ -929,8 +930,8 @@
     var name = encodeURIComponent(
       (arguments[1] && arguments[1].name) ? arguments[1].name : element.id);
-    
+
     if (options.tree) {
       return Sortable.tree(element, arguments[1]).children.map( function (item) {
-        return [name + Sortable._constructIndex(item) + "[id]=" + 
+        return [name + Sortable._constructIndex(item) + "[id]=" +
                 encodeURIComponent(item.id)].concat(item.children.map(arguments.callee));
       }).flatten().join('&');
@@ -941,5 +942,5 @@
     }
   }
-}
+};
 
 // Returns true if child is contained within element
@@ -948,7 +949,7 @@
   if (child.parentNode == element) return true;
   return Element.isParent(child.parentNode, element);
-}
-
-Element.findChildren = function(element, only, recursive, tagName) {   
+};
+
+Element.findChildren = function(element, only, recursive, tagName) {
   if(!element.hasChildNodes()) return null;
   tagName = tagName.toUpperCase();
@@ -966,7 +967,7 @@
 
   return (elements.length>0 ? elements.flatten() : []);
-}
+};
 
 Element.offsetSize = function (element, type) {
   return element['offset' + ((type=='vertical' || type=='height') ? 'Height' : 'Width')];
-}
+};
