/**
*
* egRadioButton Class
*/
function egRadioButton(id, title, posX, posY, width, height, container, name, value, checked) {
	 this.objName = 'radioButton_'+id;
	 this.id = id;
	 this.name = name;
	 this.value = value;
	 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.checked = checked;

	 this.addSibling = egRadioButton_addSibling;
	 this.setClassName = egRadioButton_setClassName;

	 this.setPressed = egRadioButton_setPressed;
	 this.setUnPressed = egRadioButton_setUnPressed;
	 this.setActive = egRadioButton_setActive;
	 this.setInactive = egRadioButton_setInactive;
	 this.setChecked = egRadioButton_setChecked;
	 this.setUnchecked = egRadioButton_setUnchecked;

	 this.getValue = egRadioButton_getValue;
	 this.setValue = egRadioButton_setValue;

	 this.onChange = egRadioButton_onChangeHandler;

	 this.siblingsList = new Array();

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

	 divRoot.innerHTML += '<div id="'+this.id+'" class="egRadioButtonUnchecked" onmouseover="javascript:' + this.objName + '.setActive();" onmouseout="javascript:' + this.objName + '.setInactive();" onmousedown="javascript:' + this.objName + '.setPressed();" onmouseup="javascript:' + this.objName + '.setUnPressed();">'+title+'</div>';
	 var inputChecked = (this.checked)?'checked':'';
	 divRoot.innerHTML += '<div style="display: none;"><input type="radio" id="'+this.id+'_value" name="'+this.name+'" value="'+this.value+'" ' + inputChecked + '></div>';
	 if(document.getElementById(this.name+'_default_value') == null) {
		 var defaultInputChecked = (this.checked)?'':'checked';
		 divRoot.innerHTML += '<div style="display: none;"><input type="radio" id="'+this.name+'_default_value" name="'+this.name+'" value="'+this.value+'" ' + defaultInputChecked + '></div>';
	 }

	 div = document.getElementById(this.id);
	 div.style.width  = width+'px';
	 div.style.left = posX+'px';
	 div.style.top  = posY+'px';
	 
	 if(checked) {
	  	this.setChecked();
	 }
	 else {
	    this.setUnchecked();
	 }
}

function egRadioButton_addSibling(egRadioButtonObject){
  if(!this.siblingsList[egRadioButtonObject.objName]) {
    this.siblingsList[egRadioButtonObject.objName] = egRadioButtonObject;
    egRadioButtonObject.addSibling(this);
  }         
}

function egRadioButton_setClassName(){
	var div = document.getElementById(this.id);
  var className = 'egRadioButton';

  if(this.checked) {
    className = className + 'Checked';
  }
  else {
    className = className + 'Unchecked';
  }
  if(this.active) {
    className = className + 'Hover';
  }
  if(this.pressed) {
    className = className + 'Pressed';  
  }
  div.className = className;
}

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

function egRadioButton_setUnPressed(){
	if(this.pressed) {
    this.pressed = 0;
    this.setClassName();
	}
  for (var i in this.siblingsList) {
    this.siblingsList[i].setUnchecked();
  }
  this.setChecked();
	egRadioButton_onChange(this.id+'_value');
}

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

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

function egRadioButton_setChecked(){
  this.checked = true;
  this.setClassName();
	document.getElementById(this.name+'_default_value').checked = false;
	document.getElementById(this.id+'_value').checked = true;
}

function egRadioButton_setUnchecked(){
  this.checked = false;
  this.setClassName();
	document.getElementById(this.name+'_default_value').checked = true;
	document.getElementById(this.id+'_value').checked = false;
}

function egRadioButton_getValue(){
	return document.getElementById(this.id+'_value').checked;
}

function egRadioButton_setValue(value){
	if(value || value > 0) {
		this.setChecked();
	}
	else {
		this.setUnchecked();
	}
}

function egRadioButton_onChangeHandler() {
}

function egRadioButton_onChange(id) {
	var append = '_value';
	egObjectsArray['radioButton_'+id.substr(0, id.length-(append.length))].onChange();
}
