/**
 * @fileoverview
 * 
 * <p>Copyright (c) 2006 Peter Michaux. All rights reserved.<br />
 * Code licensed under the MIT License:<br />
 * http://michaux.ca/svn/dragdrop/trunk/MIT-LICENSE.txt</p>
 *
 * @author Peter Michaux - http://peter.michaux.ca
 * @version 0.1 (August 2006)
 */

/**
 * @object
 *
 * <p>The DragHandles object is designed to have it's properties dynamically
 * added to an instance of DragManager or a subclass of DragManager. By dynamically
 * adding these properties the Manager will gain handle functionality for
 * all draggables.</p>
 *
 * <p>To add the handle functionality, the following DragHandle
 * properites will overwrite DragManager's properties.<p>
 *
 * <ul>
 *   <li>onDraggable()</li>
 * </ul>
 *
 * <p>After including DragHandles in the DragManager instance, a draggable
 * must have one or more html elements with class name "handle". These elements
 * are sensitive to mousedown events for selection and initiating a drag.</p>
 */
DragHandles = {
    
  isHandle: function(element) {
    return (YAHOO.util.Dom.hasClass(element, "handle")) ? true : false;
  },
  
  onDraggable: function(e) {
    var handle_flag = false;
  	var targ = YAHOO.util.Event.getTarget(e);
    while (targ) {
  		if (!handle_flag && this.isInvalidHandle(targ)) {
  		  return null;
  		}
  		if (this.isHandle(targ)) {
  		  handle_flag = true;
  		}
  		if (handle_flag && this.isDraggable(targ)) {
  		  return targ;
  		}
  		targ = targ.parentNode;
  	}
  	return null;
  }
  
};