function Apple(id, group) {
  // Call the DDProxy constructor.
  // The use of extend function below makes this possible.
  Apple.superclass.call(this, id, group);
  this.selected = false;
  Apple.apples.push(this);
}
// The extend function is defined in the extend.js file
extend(Apple, YAHOO.util.DDProxy);

// Keep a record of all instances of Apple
Apple.apples = [];

// If you click off of the apples then everything is unselected
YAHOO.util.Event.addListener(document, "mousedown",
                             function(){Apple.unselectAll();});


// Methods for managing the multi select

Apple.prototype.select = function() {
  this.selected = true;
  // Can use CSS to style the selected apples
  YAHOO.util.Dom.addClass(this.getEl(), 'selected');
};

Apple.selected = function() {
  var i, apple;
  var selected = [];
  for (i=0; i<Apple.apples.length; i++) {
    apple = Apple.apples[i];
    if (apple.selected) {
      selected.push(apple);
    }
  }
  return selected;
};

Apple.prototype.unselect = function() {
  if (this.selected) {
    this.selected = false;
    YAHOO.util.Dom.removeClass(this.getEl(), 'selected');
  }
};

Apple.unselectAll = function() {
  var i;
  for (i=0; i<Apple.apples.length; i++) {
    Apple.apples[i].unselect();
  }  
};


// Methods to override methods of DDProxy

Apple.prototype.onMouseDown = function(e) {
  var mac;
  if (!this.selected) {
    // see http://www.javascripter.net/faq/operatin.htm
    mac = (navigator.appVersion.indexOf("Mac")!==-1) ? true : false;
    if ((mac && !e.metaKey) || (!mac && !e.ctrlKey)) {
      Apple.unselectAll();
    }
    this.select();
  }
};

Apple.prototype.startDrag = function(e) {
  // innerHTML is considered evil by some. Could use DOM instead to insert.
  this.getDragEl().innerHTML= Apple.selected().length;
};

// If you want the target to handle what happens when the drop occurs,
// just send the selected apple objects to a method of the target
//
//Apple.prototype.onDragDrop = function(e, id) {
//  Yahoo.util.DragDropMgr.getDDById(id).takeThese(Apple.selected());
//};

Apple.prototype.endDrag = function(e) {
  Apple.unselectAll();
};

Apple.prototype.showFrame = function(x, y) {
  this.getDragEl().style.visibility = "";
};

Apple.prototype.setDragElPos = function(x, y) {
  var proxy = this.getDragEl();
  var r = YAHOO.util.Dom.getRegion(proxy);
  YAHOO.util.Dom.setXY(proxy, [x-((r.right-r.left)/2), y-((r.bottom-r.top)/2)]);
};
