/**
*
* egPressButton Class
*/
var focussedButton = null; 

function egPressButton(id, title, posX, posY, width, height, action, container) {
	 this.objName = 'pressButton_'+id;
	 this.id = id;

	 this.x = posX;
	 this.y = posY;
	 this.width = 0;
	 this.height = 0;
	
	 this.getHeight = egWindow_getHeight;
	 this.getWidth  = egWindow_getWidth;

	 this.show = egWindow_show;
	 this.hide = egWindow_hide;
	 this.moveTo = egWindow_moveTo;
	 this.displayAt = egWindow_displayAt;

	 this.active = 0;
	 this.pressed = 0;
	 this.focussed = 0;

	 this.setClassName = egPressButton_setClassName;

	 this.setPressed = egPressButton_setPressed;
	 this.setUnPressed = egPressButton_setUnPressed;
	 this.setActive = egPressButton_setActive;
	 this.setInactive = egPressButton_setInactive;
	 this.setFocussed = egPressButton_setFocussed;
	 this.setUnfocussed = egPressButton_setUnfocussed;

   if (!container) {
      container = 'easy-GUI_mainLayer';
   }
	 divRoot = document.getElementById(container);

	 divRoot.innerHTML += '<div id="'+this.id+'" class="egPressButtonFrame" onmouseover="javascript:' + this.objName + '.setActive();" onmouseout="javascript:' + this.objName + '.setInactive();" onmousedown="javascript:' + this.objName + '.setPressed();" onmouseup="javascript:' + this.objName + '.setUnPressed();' + action + ';">'
    + '  <div id="'+this.id+'_button" class="egPressButton">'+title+'</div>'
    + '  <div id="'+this.id+'_stop" class="egPressButtonStop"></div>'
    + '  <div style="position: absolute; left: 0; top: 0; width: '+width+'px; height: 100%; z-index: 100;">&nbsp;</div>'
    + '</div>';

	 div = document.getElementById(this.id);
	 div.style.width  = width+'px';
	 div.style.left = posX+'px';
	 div.style.top  = posY+'px';
   div = document.getElementById(this.id+'_button');
	 div.style.width  = (width-8)+'px';
}

function egPressButton_setClassName(){
	var div1 = document.getElementById(this.id+'_button');
	var div2 = document.getElementById(this.id+'_stop');
  var className1 = 'egPressButton';
  var className2 = 'egPressButtonStop';

  if(this.focussed && !this.active && !this.pressed) {
    className1 = className1 + 'Focussed';
    className2 = className2 + 'Focussed';
  }
  if(this.active) {
    className1 = className1 + 'Hover';
    className2 = className2 + 'Hover';
  }
  if(this.pressed) {
    className1 = className1 + 'Pressed';
    className2 = className2 + 'Pressed';
  }
  div1.className = className1;
  div2.className = className2;
}

function egPressButton_setPressed(){
	if(!this.pressed) {
    this.pressed = 1;
    this.setClassName();
	}
  this.setFocussed();
}

function egPressButton_setUnPressed(){
	if(this.pressed) {
    this.pressed = 0;
    this.setClassName();
	}
}

function egPressButton_setActive(){
	if(!this.active) {
    this.active = 1;
    this.setClassName();
	}
}

function egPressButton_setInactive(){
	if(this.active) {
    this.active = 0;
    this.setClassName();
	}
}

function egPressButton_setFocussed(){
	if(focussedButton) {
		focussedButton.setUnfocussed();
	}
	if(!this.focussed) {
		focussedButton = this;
    this.focussed = 1;
    this.setClassName();
	}
}

function egPressButton_setUnfocussed(){
	if(this.focussed) {
    this.focussed = 0;
    this.setClassName();
	}
}
