	var pollable = Class.create({
		
		initialize: function(container){
			this.instID = 'pollable.' + parseInt(Math.random()*1000000);
			this.container = $(container);
			document.observe('dom:loaded', this.init.bind(this));
		},
		
		init : function(){
			// gather elements:
			if (!this.voted){
				this.answers = this.container.select('.pollRadio');
				this.submitter = this.container.select('.pollSubmit')[0];
				this.resultsButton = this.container.select('.showResults')[0];
				this.resultsButton.observe('click',(function(){ this.showResults(''); }).bind(this)	);
				this.submitter.observe('click', this.saveVote.bindAsEventListener(this));
			}
			this.questionID = parseInt(this.container.getAttribute('id'));
		},
		
		saveVote : function(event){
			var elem = event.element();
			// seek checked elem:
			var checked = this.answers.findAll(
				(function(elem){
					if (elem.getValue() == 'on'){
						return elem;
					}
				}).bind(this)
			)
			if (checked.length < 1){
				return;
			}
			checked = parseInt(checked[0].getAttribute('id'));
			var wpsRPC = new wps.rpc;
			wpsRPC.debug = true;
			wpsRPC.createCall('poll', this.showResults.bind(this) , this);
			wpsRPC.call('storeAnswer', 'questionID=' + this.questionID, 'answerID=' + checked );
		},
		
		showResults : function(req){
			if (req){
				$(this.questionID + "_answers").update("");
				$(this.questionID + "_pollResults").update(req.responseText);
			}else{
				var wpsRPC = new wps.rpc;
				wpsRPC.debug = true;
				wpsRPC.createCall('poll', this.showResults.bind(this) , this);
				wpsRPC.call('storeAnswer', 'questionID=' + this.questionID);
			}
		}
		
	})
