var RadioField = new Class({
	
	Extends: FormField,

	radioOptions: undefined,
	value		: undefined,
	radioFields	: new Hash(),
	
	
	initialize: function(name, label, options, radioOptions)
	{
		this.radioOptions = radioOptions;
		this.parent(name, label, options);
	},
	
	createField: function()
	{
		this.wrapper 			= new Element("div", {"class":"fieldContainer"});
		this.labelElement		= new Element("label", {text:this.label}).inject(this.wrapper);
		this.optionsContainer	= new Element("div", {"class":"optionsContainer"}).inject(this.wrapper);
		
		if($defined(this.radioOptions))
		{
			this.createOptions();
		}
	},
	
	createOptions: function()
	{
		this.optionsContainer.set("html", "");
		$H(this.radioOptions).each(this.createOption.bind(this));
	},
	
	createOption : function(option, name)
	{
		var radioContainer  = new Element("div", {"class":"radioContainer"}).inject(this.optionsContainer);
		var field			= new Element("input", {type:"radio", value:option.value, name:this.name}).inject(radioContainer);
		var label 			= new Element("label", {text:option.label, "class":name}).inject(radioContainer);
		
		field.addEvent("change",this.check.bind(this, [option.value]));
		label.addEvent("click",this.check.bind(this, [option.value]));
		
		this.radioFields[option.value] = field;
	},
	
	setRadioOptions: function(options)
	{
		this.radioOptions = options;
		this.createOptions();
	},
	
	getValue: function()
	{
		return this.value;
	},
	
	check: function(value)
	{
		this.setValue(value);
		this.fieldBlur();
	},
	
	setValue: function(value)
	{
		if(!$defined(this.radioFields[value]))
		{
			return false;
		}
		this.radioFields.each(function(field){field.checked = false});
		this.radioFields[value].checked = true;
		this.value = value;
	}
})