
$(document).ready(function() { 
  $("#votebutton").click(function() {

      var $formdata = $("#pollform").serialize();
 
      if ($("input:radio", "#pollform").is(':checked')) {
        $.ajax({
          url: "/ajax/poll?ajax=1&" + $formdata,
          type: "GET",
          datatype: "html",
          async: true,
  
          success: function(data) {
            $('#inner').html(data);
          }
        });
      }
      return false;
  });

  $("#viewresults").click(function() {
        $.ajax({
          url: "/ajax/poll?ajax=1&pollresult=" + $("#poll_id").val(),
          type: "GET",
          datatype: "html",
          async: true,
  
          success: function(data) {
            $('#inner').html(data);
          }
        });

      return false;
  });

  $('<div id="loading"><img src="/media/ajax-loader.gif" alt="Loading..." /></div>').insertBefore('#poll #inner').ajaxStart(function() {
    $('#poll #inner').empty();
    $(this).show();
  }).ajaxStop(function() {
    $(this).hide(); 
  });


  $('#votebutton').hover(function() {
    $(this).addClass('hover');
  }, function() {
    $(this).removeClass('hover');
  });

});
  
