if(!$defined(UI))
	var UI = {};

UI.Poll = new Class({
	
	version: "1.03",
	
	Implements: Options,
	options:	{
		url: '/AJAX/poll.aspx'
	},
	
	initialize: function(selector, options)	{
		this.selector = selector;
		this.setOptions(options);
		this.wireUp();
		document.id(document).store('ui:poll:version', this.version);
	},
	
	wireUp: function()	{
		var self = this;
		$$(this.selector).getElement('FORM').addEvent('submit', function()	{
			var poll = this.getParent(self.selector);
			this.set('send', {
				onRequest: function()	{
					poll.setAsLoading();
				},
				onSuccess: function(reply)	{
					poll.set('html', reply);
					poll.set('html', poll.getElement(self.selector).get('html'));
					poll.stopAsLoading();
					self.wireUp();
				}
			});
			this.send(self.options.url);
			return false;
		});
	}

});


window.addEvent('domready', function()	{
		new UI.Poll('.poll');
});
