/*
 * 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.DropDown = Class.create();

Af.DropDown.prototype = {
   initialize: function(handler, div, container, title) {
      this._initializeDialog(handler, div, container, title);
   },
   
   _initializeDialog: function(handler, div, container, title) {
      this.handler = handler;
      this.content = div;
      this.container = container;
      this.title = title;
      this.content.onclick = this.mouseClicked.bindAsEventListener(this);
      this.width="60px";
   },

   
   mouseClicked: function(e) {
      if (this.handler != null && this.handler.dropDownClicked != null) {
         this.handler.dropDownClicked(this, e);
      }
   },
   
   close: function(ev) {
      this.hide();
   },
   
   hide: function() {
      this.visible = false;
      if (this.element != null) {
         this.element.style.display = "none";
      }
   },
   
   
   show: function(x, y) {
      this.visible = true;
      if (this.element == null) {
         this.createElement();
      }
      
      this.container.appendChild(this.element);
      this.element.style.left = x + "px";
      this.element.style.top = (y + 2)+ "px";
      this.element.style.display = "";
   },
   
   createElement: function() {
      
      var table = document.createElement('table');
      table.cellSpacing = '0px';
      table.cellPadding = '0px';
      table.className = 'Dialog';
      if (this.width) {
         table.style.width = this.width;
      }
      if (this.height) {
         table.style.height = this.height;
      }
      
      var tbody = document.createElement('tbody');
      table.appendChild(tbody);
      
      var td;
      var tr;
      
      tr = document.createElement('tr');
      tbody.appendChild(tr);
      td = document.createElement('td');
      td.className = 'DialogTitle';
      tr.appendChild(td);
      this.titleElement = td;
      this.titleElement = td;
	  var span = document.createElement('span');
	  span.innerHTML = this.title;
	  span.className = "DialogTitleSpan";
	  td.appendChild(span);
      
      this.cb = document.createElement('a');
      this.cb.className = 'DialogTitleButton';
      var img = document.createElement('img');
      img.className = 'DialogCloseButtonImage';
      img.src = '/images/close.gif';
      this.cb.appendChild(img);
      td.appendChild(this.cb);
      this.cb.onclick = this.close.bindAsEventListener(this);
      
      tr = document.createElement('tr');
      tbody.appendChild(tr);
      td = document.createElement('td');
      td.colSpan = "2";
      tr.appendChild(td);
      this.content.style.width = "100%";
      this.content.style.display = "";
      td.appendChild(this.content);
      
      this.element = table;
      
   }
}
