// 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 = Class.create(Draggable, {
    initialize: function($super,element,options) {
        $super(element,options);
        this.element.undoPositioned();
        if( typeof(this.options.dragelement) == 'undefined' ) this.options.dragelement = false;
    },
    initDrag: function($super,event) {
        this.dragging = true;
        if( this.options.dragelement ){
            this._originalElement = this.element;
            this.element = this.options.dragelement(this.element);
            this.element.absolutize();
            this.element.clonePosition(this._originalElement);
        }

        $super(event);
    },
    finishDrag: function($super,event, success) {
        this.dragging = false;
        $super(event, success);

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

function getDragElement(element){
    var clone = element.cloneNode(true);
    clone.id = 'clone_'+element.id;
    $('cloneHolder').innerHTML = '';
    $('cloneHolder').insert(clone,'top');

    element.setStyle({
        background: '#e4d7c7',
        border: '#bdaf9e 2px dashed',
        color: '#e4d7c7',
        height: '23px',
        width: '316px'
    });

    clone.setStyle({
    	background: '#fffff1 url(../i/finder-drag-icon-light.gif) no-repeat 284px 14px',
    	border: '#53493d 1px solid',
	    color: '#50463c',
	    margin: 0,
	    opacity: 0.5
    });


    return clone;
}
//new SubsDraggable('dragableElementId', {handle:'draghandle', dragelement:getDragElement});