$.widget( 'm2.poll', {

    form: null,
    action: null,

    _create: function() {
        this.form = this.element.find('form');
        if (this.form) {
            this.action = this.form.attr('action');
            this._addEvents();
        }
    },

    _addEvents: function() {
        this.form.submit(
            $.proxy(function(event) {
                event.preventDefault();
                this.vote();
                return false;
            }, this));
    },

    vote: function() {
        var a = this.action + ',action.vote';

        $.post(a, this.form.serialize(), $.proxy(function(data) {
            var r = jQuery.parseJSON(data);
            if (r.isError == 0) {
                this.element.html(r.data);
                this._addEvents();
            }
        }, this));
    },

    results: function() {
        
    },

    reload: function() {
        var a = this.options.url + ',action.show';
        $.getJSON(a, $.proxy(function(response) {
            if (response.isError == 0) {
                this.element.html(response.data);
                this._addEvents();
            }
        }, this));
    }
});
