// extentions for scriptaculous dragdrop.js
Object.extend(Class, {
    superrise: function(obj, names){
        names.each( function(n){ obj['super_' + n] = obj[n] } )
        return obj;
    }
})

// Draggable that allows substitution of draggable element
var SubsDraggable = Class.create();
SubsDraggable.prototype = Object.extend({}, Draggable.prototype);
Class.superrise(SubsDraggable.prototype, ['initialize', 'startDrag', 'finishDrag'])
Object.extend( SubsDraggable.prototype , {
    initialize: function(event) {
        this.super_initialize.apply(this, arguments);
        if( typeof(this.options.dragelement) == 'undefined' ) this.options.dragelement = false;
    },
    startDrag: function(event) {
      if( this.options.dragelement ){
            this._originalElement = this.element;
            this.element = this.options.dragelement(this.element);
//            Position.absolutize(this.element);
//            Position.clone(this._originalElement, this.element);
      }
//      console.debug('here');
      this.super_startDrag(event);
    },
    finishDrag: function(event, success) {
        this.super_finishDrag(event, success);

        if(this.options.dragelement){
            Element.remove(this.element);
            this.element = this._originalElement;
            this._originalElement = null;
        }
    }
})

function getDragElement(element, event) {
    var el = element.cloneNode(true);
    el.id = 'sub'+element.id;
    el.style.position = 'relative';
    $('fakeiFrame').appendChild(el);
    return el;
}

/*
// Draggable that allows substitution of draggable element
var SubsDraggable = Class.create();
SubsDraggable.prototype = Object.extend({}, Draggable.prototype);
Class.superrise(SubsDraggable.prototype, ['initialize', 'startDrag', 'finishDrag'])
Object.extend( SubsDraggable.prototype , {
    initialize: function(event) {
        this.super_initialize.apply(this, arguments);
        if( typeof(this.options.dragelement) == 'undefined' ) this.options.dragelement = false;
    },
    startDrag: function(event) {
      if( this.options.dragelement ){
            this._originalElement = this.element;
            this.element = this.options.dragelement(this.element, event);
//            Position.absolutize(this.element);
//            Position.clone(this._originalElement, this.element);
      }
      this.super_startDrag(event);
    },
    finishDrag: function(event, success) {
        this.super_finishDrag(event, success);

        if(this.options.dragelement){
            Element.remove(this.element);
            this.element = this._originalElement;
            this._originalElement = null;
        }
    }
})


*/