-$(".votable").delegate ".vote[data-role=create]", "ajax:success", (e, data, textStatus, jqXHR) ->
+$('.votable').delegate '.vote[data-role=create]', 'ajax:success', (e, data, textStatus, jqXHR) ->
   voteCallback.call(this, data)
-$(".votable").delegate ".vote[data-role=delete]", "ajax:success", (e, data, textStatus, jqXHR) ->
+$('.votable').delegate '.vote[data-role=delete]', 'ajax:success', (e, data, textStatus, jqXHR) ->
   unvoteCallback.call(this, data)
-$(".votable").delegate ".vote", "ajax:error", (e, data, textStatus, jqXHR) ->
+$('.votable').delegate '.vote', 'ajax:error', (e, data, textStatus, jqXHR) ->
   voteErrorCallback.call(this, data)
-$(".votable").delegate ".vote", "ajax:beforeSend", (e, data, textStatus, jqXHR) ->
+$('.votable').delegate '.vote', 'ajax:beforeSend', (e, data, textStatus, jqXHR) ->
   if $('body').hasClass('loading')
     return false
   $('body').addClass('loading')

  $('body').removeClass('loading')
  $(".flash").append($("<div id=flash-error>#{data.statusText}</div>"))



window.unvoteCallback = (data) ->
  $('body').removeClass('loading')
  $(this).attr('data-role','create')
  $(this).attr('action','/votes')
  $(this).find('input[value=delete]').remove()
  if($(this).data('hover'))
    $(this).one 'mouseout', ->
      $(this).find('input.unvote').removeClass('unvote').addClass('vote')
  else
    $(this).find('input.unvote').removeClass('unvote').addClass('vote')
  id = $(this).parent().data('id')
  $(".vote-count[data-id=#{id}]").text(parseInt($(".vote-count[data-id=#{id}]").text()) - 1 )

