/*
 * Author: Vertex Logic, Inc
 * Copyright 2005, 2006, 2007 - All rights reserved
 *
 * Vertex Logic, Inc., California, USA 
 *
 * Vertex Logic grants you ("Licensee") a non-exclusive license to use
 * and modify this source and recompile it in
 * accordance with the terms of the Agreement under which this software is bought
 * and provided that (i) this copyright notice appear on all copies of the Software; 
 * (ii) Licensee does not sale the software as is or with modification without
 * the prior consent of Vertex Logic. (iii) Licensee agrees that it does not have any 
 * title or ownership of the Software.
 *
 * The program is provided "as is" without any warranty express or
 * implied, including the warranty of non-infringement and the implied
 * warranties of merchantibility and fitness for a particular purpose.
 * Vertex Logic will not be liable for any damages suffered 
 * by you as a result of using the Program. 
 * In no event will Vertex Logic be liable for any
 * special, indirect or consequential damages or lost profits even if
 * Vertex Logic have been advised of the possibility of their occurrence. 
 * Vertex Logic will not be liable for any third party claims against you.
 */
 Af.DndMgr2 = Class.create();

Af.DndMgr2.prototype = {
   initialize: function(handler) {
       this.dtable = new Array();
       this.draggableElement = document.createElement('div');
       this.draggableElement.style.border = "1px dashed black";
       this.draggableElement.style.padding = "2px";
       this.draggableElement.style.textAlign = "center";
       this.draggableElement.style.backgroundColor = "#ffffff";
       this.draggableElement.style.fontSize = "10px";
       this.draggableElement.style.width = "100px";
       this.draggableElement.style.height = "12px";
       this.draggableElement.style.overflow = "hidden";
       this.dndMgr = new Rico.DragAndDrop();
       this.dndMgr.dragStartX_Delta = 5;
	   this.dndMgr.dragStartY_Delta = 5;
       this.handler = handler;
   },
   
   registerDraggable: function(type, key, element, text) {
	   var draggable = new Af.Draggable(type, key, element, false, this.draggableElement, text);
	   draggable.allowedTarget = element;
       this.dndMgr.registerDraggable(draggable);
       return draggable;
   },
   
   registerDropZone: function(type, element, handler) {
       var dropzone = new Af.Dropzone(handler ? handler : this.handler, element, type);
       this.dndMgr.registerDropZone(dropzone);
       return dropzone;
   },
   
   registerDropZone2: function(dropzone) {
       this.dndMgr.registerDropZone(dropzone);
   },
   
   deregisterDropZone: function(dropzone) {
       this.dndMgr.deregisterDropZone(dropzone);
   },
   
   clearAll: function() {
       this.dndMgr.clearDropZones();
       this.dndMgr.clearDraggables();
   },
   
   clearDraggables: function() {
       this.dndMgr.clearDraggables();
   },
   
   clearDropZones: function() {
       this.dndMgr.clearDropZones();
   }
}

Af.Draggable = Class.create();

Af.Draggable.prototype = Object.extend(new Rico.Draggable(), {
   initialize: function( type, key, htmlElement, repositionable, de, text) {
      this.type          = type;
      this.key = key;
      this.htmlElement   = htmlElement;
      this.text = text;
      if (this.text == null) {
         this.text = "";
      }
      this.selected      = false;
	  this.draggableElement = de;
	  this.allowedTarget = null;
	  if (repositionable != null) {
	     this.repositionable = repositionable;
	  } else {
		 this.repositionable = false;
	  }
   },

   startDrag: function() {
	   //this.draggableElement.style.width = this.htmlElement.offsetWidth + "px";
	   //this.draggableElement.style.height = this.htmlElement.offsetHeight + "px";
	   this.draggableElement.innerHTML = this.text;
   },
   
   select: function() {
      this.selected = true;
      this.showingSelected = true;
   },

   deselect: function() {
      this.selected = false;
      if ( !this.showingSelected )
         return;
      this.showingSelected = false;
   }
})

