var mooRadioGroup = new Class
({
	collection: false,
	
	initialize: function(collection, defaultValue)
	{
		this.collection = collection;
		var parent = collection[0].getParent();
		
		var preselect = false;
		
		collection.each(function(el) {
			var radio = new Element('div', {
				'class': 'mooRadioDiv',
				id: el.get('id')+'-mooRadio',
				events: {
					click: function() {
						collection.each(function(el) {
							if (el.get('id')+'-mooRadio' == this.get('id')) {
								this.addClass('selected');
								el.set('checked', 'checked');
							} else {
								$(el.get('id')+'-mooRadio').removeClass('selected');
								el.set('checked', null);
							}
						}.bind(this));
					}
				}
			}).store('value', el.get('value'));
			
			radio.inject(parent, 'bottom');
			if (radio.retrieve('value') == defaultValue) preselect = radio;
			
		}.bind(this));
		
		if (preselect) preselect.fireEvent('click');
	}
});

