// poll
$(function() {

  
  $("#poll-submit").click(function() {
    var id_vote = $("#id_vote").val();
    var vote_answer = new Array; 
    
    // Проверяем чтобы хотя бы один ответ был выбран
    if ($("input[@name='vote_answer[]']:checked").length == 0)
    {
	    // msg
	    $("#active-poll #msg").text('Выберите ответ').removeClass().addClass('green').fadeIn("slow");
	    setTimeout("$('#active-poll #msg').fadeOut();", 1000);
          
        return false;
    }
    
    // Формируем список результатов
    $("input[@name='vote_answer[]']:checked").each(
    		function(i)
    		{
    			vote_answer[vote_answer.length] = this.value;
    		}
    	);
    
    $("#active-poll #inputs").hide();
    $("#active-poll #wait").show();
    
    $.post("/polls/",  { 'action': 4, 'id_vote': id_vote, 'vote_answer[]': vote_answer },  
	    function(data){
	      $("#active-poll #wait").hide();
	        
	      // msg
	      $("#active-poll #msg").text('Ваш голос принят.').removeClass().addClass('green').fadeIn("slow");
	      setTimeout("$('#active-poll #msg').fadeOut();", 2000);
	       
	        
	      // results
	      $("#active-poll .results").get(0).innerHTML = data;
	           
	      // show
	      $("#active-poll .choices").slideUp(function(){
	          $("#active-poll .results").slideDown('slow');            
	      });
	    }
    );
    
  });
 
});