var Poll = new Class({
	
	radios:{},
	reps:{},
	current:null,
	
	initialize: function(name) {
		
		if (!$(name))
			return;
		
		var radios = $(name).getElements('input[type=radio]');
		var links = $(name+'Replace')
		
		if (links)
			links = links.getElements('a');
			
		radios.each(function(el) {
			this.radios[el.get('value').toLowerCase()] = el;
		}.bind(this));
		
		links.each(function(el) {
			var key = el.get('rel').toLowerCase();
			this.reps[key] = el;
			el.set('href', 'javascript:void(0);')
			el.addEvent('click', this.onClick.bind(this, key));
		}.bind(this));
	},
	
	onClick: function(key) {
		
		if (this.current == key)
			return
		
		if (this.current) {
			this.radios[this.current].set('checked', false);
			this.reps[this.current].removeClass('selected');
		}
		
		this.radios[key].set('checked', true);
		this.reps[key].addClass('selected');
		
		this.current = key;
	}
});

window.addEvent('load', function() {
new Poll('select1');
new Poll('select2');
new Poll('select3');
new Poll('select4');
new Poll('select5');
});