var Votes = Class.create();

Votes.prototype = {
    
    initialize: function(voteId, voteBlock, voteResult) {        
        
        this.voteId = voteId;
        this.voteBlock = voteBlock;
        this.voteResult = voteResult;        
    },
    
    submit: function() {
    
        var variantId = '';
    
        var inputs = Form.getInputs($(this.voteBlock + this.voteId), 'radio');
        for (var inputIndex = 0; inputIndex < inputs.length; inputIndex++) {
            
            var input = inputs[inputIndex];
            if (input.checked) {
            
                variantId = input.value;
            }            
        }
        
        if (variantId != '') {        
                    
		    var url = '/ajax/votes/';
		    var pars = 'bx[plugins][votes][' + this.voteId + ']=' + variantId;				    

            Effect.Fade($(this.voteBlock + this.voteId));
            
		    var myAjax = new Ajax.Request(
					url, 
					{method: 'post', parameters: pars, onComplete: this.results.bind(this)}
					);
        }
    },
    
    results: function(request) {      
    
        var container = $(this.voteBlock + this.voteId).parentNode;
        container.innerHTML = request.responseText;       
        
    }
}