/* Copyright (c) 2006 Yahoo! Inc. All rights reserved. */
/* HIGHLY HACKED UP BY jfriedl@yahoo.com */

/**
 * @class a YAHOO.util.DDProxy implementation. During the drag over event, the
 * dragged element is inserted before the dragged-over element.
 *
 * @extends YAHOO.util.DDProxy
 * @constructor
 * @param {String} id the id of the linked element
 * @param {String} sGroup the group of related DragDrop objects
 */
YAHOO.example.DDList = function(id, sGroup, config) {
    if (id) {
        this.init(id, sGroup, config);
        this.initFrame();
    }
};

// YAHOO.example.DDList.prototype = new YAHOO.util.DDProxy();
YAHOO.extend(YAHOO.example.DDList, YAHOO.util.DDProxy);

YAHOO.example.DDList.prototype.startDrag = function(x, y) {
      var clickEl = this.getEl();
      clickEl.style.border = "1px solid red";
      clickEl.style.color = "#FAA";
};

YAHOO.example.DDList.prototype.endDrag = function(e) {
      var clickEl = this.getEl();
      clickEl.style.border = "1px solid #444";
      clickEl.style.color = '#CCC';
};

YAHOO.example.DDList.prototype.onDrag = function(e, id) {
   
};

YAHOO.example.DDList.prototype.onDragOver = function(e, id) {
    if (id == 'trash')
         return;

    var el;
    if ("string" == typeof id)
        el = YAHOO.util.Dom.get(id);
    else
        el = YAHOO.util.DDM.getBestMatch(id).getEl();
    
    var mid = YAHOO.util.Dom.getY(el) + Math.floor(el.offsetHeight / 2);

    //YAHOO.log("ID["+id+"]  getpagey["+YAHOO.util.Event.getPageY(e)+"] < mid[" + mid + "]");

    if (YAHOO.util.Event.getPageY(e) < mid)
    {
        if (this.getEl().nextSibling == el) {
            //YAHOO.log("not moving before: " + this.getEl().id + " --> " + el.id);
        } else {
            el.parentNode.insertBefore(this.getEl(), el); // insertBefore(newchild, before oldchild)
            on_data_change();
            //YAHOO.log("MOVING BEFORE: " + this.getEl().id + " --> " + el.id);
        }
    }
    else
    {
        if (this.getEl() == el.nextSibling) {
            //YAHOO.log("not moving after: " + this.getEl().id + " --> " + el.id);
        } else {
            //YAHOO.log("MOVING AFTER: " + this.getEl().id + " --> " + el.id);
            el.parentNode.insertBefore(this.getEl(), el.nextSibling); // insertBefore(newchild, before oldchild)
            on_data_change();
        }
    }
};


YAHOO.example.DDList.prototype.toString = function() {
    return "DDList " + this.id;
};


/////////////////////////////////////////////////////////////////////////////

YAHOO.example.DDListBoundary = function(id, sGroup, config) {
    if (id) {
        this.init(id, sGroup, config);
        this.isBoundary = true;
    }
};

YAHOO.example.DDList.prototype.onDragEnter = function(e, id) { };
YAHOO.example.DDList.prototype.onDragOut   = function(e, id) { };


YAHOO.extend(YAHOO.example.DDListBoundary, YAHOO.util.DDTarget);

YAHOO.example.DDListBoundary.prototype.toString = function() {
    return "DDListBoundary " + this.id;
};


