/*****************************************************************\
* Product:   JavaScript Framework                                 *
* File:      startbutton.js                                       *
* Author:    Ties Pull ter Gunne                                  *
* Copyright: (c) 1999 Ties Pull ter Gunne                         *
* License:   No Restrictions                                      *
\*****************************************************************/

//=============== class StartButton ======================

function StartButton(name,label,menu) {
  // properties
  this.name = name;
  this.pressed = false;
  this.backgroundColor = "#C0C0C0";
  this.borderColor = "#E0E0E0";
  this.border = "3px";
  this.activeStyle = "inset";
  this.borderStyle = "outset";
  this.color = "#000000";
  this.label = label;
  this.elem = null;
  this.menu = menu;
  this.align = "right";
  this.valign = "top";
  if (menu != null) {
    this.menu.activator = this;
  }
}

StartButton.prototype = new Element;

//====== internet explorer methods ========

StartButton.prototype.validate = function() {
  document.write('<STYLE Type="text/css">\n');
  document.write('  .StartButton {\n');
  document.write('    position:absolute;\n');
  document.write('    background-color:'+this.backgroundColor+';\n');
  document.write('    border:'+this.border+';\n');
  document.write('    border-style:'+this.borderStyle+';\n');
  document.write('    border-color:'+this.borderColor+';\n');
  document.write('    visibility:hidden;');
  if (this.fontFamily != null)
    document.write('    font-family:'+this.fontFamily+';\n');
  if (this.image != null)
    document.write("    background-image:\"url('"+this.image+"')\";\n");
  document.write('    color:'+this.color+';\n');
  document.write('    padding:2px;\n');
  document.write('    cursor:pointer;\n');
  document.write('    text-align:center;\n');
  document.write('    left:'+this.left+';\n');
  document.write('    top:'+this.top+';\n');
  document.write('  }\n');
  document.write('</STYLE>\n');
}

StartButton.prototype.init = function() {
  this.elem = document.getElementById(this.name);
  this.baseElem = this.elem;
  this.elem.guard = this;
  this.elem.style.width = this.elem.scrollHeight;
  this.elem.style.visibility = "visible";
  this.elem.onclick = this.press;
}

StartButton.prototype.locate = function(x,y) {
  this.left = x;
  this.top = y;
  document.write("\n<DIV ID=\"" + this.name + "\" Class=\"StartButton\">");
  document.write('\n<TABLE>\n<TR Align="center">\n<TD>');
  document.write(this.label);
  document.write("\n</TD>\n</TR>\n</TABLE>");
  document.write("\n</DIV>");
}

StartButton.prototype.moveTo = function(x,y) {
  this.elem.style.top = y;
  this.elem.style.left = x;
}

StartButton.prototype.stop = function() {
  if (this.pressed) {
    this.elem.style.borderStyle = this.borderStyle;
    if (this.menu != null) 
      this.menu.hide();
    this.pressed = !this.pressed;
  }
}

StartButton.prototype.start = function() {
  this.elem.style.borderStyle = this.activeStyle;
  if (this.menu != null) 
    this.menu.placeNear(this);
}

StartButton.prototype.press = function(evt) {
  if (this.guard.action != null) {
    this.guard.action();
  } else {
    if (this.guard.pressed) {
      this.style.borderStyle = this.guard.borderStyle;
      if (this.guard.menu != null) 
        this.guard.menu.hide();
    } else {
      this.style.borderStyle = this.guard.activeStyle;
      if (this.guard.menu != null) 
        this.guard.menu.placeNear(this.guard);
    }
  }
  this.guard.pressed = !this.guard.pressed;
  if (evt == null) {
    evt = event;
  }
  evt.cancelBubble = true;
}


