$(document).ready(function() {
  $("#toollike a").click(function(event) {
    event.preventDefault();
    // Se ha la classe e clicca, vuole toglierlo (vote => false)
      var a = this;
      var vote = !$(this).hasClass("selected");
      var post_id = $(this).attr("class").match(/.*post-(\d+)/)[1];
      $.post(post_vote_path, {
        vote : vote,
        post_id : post_id
      }, function(data, textStatus) {
        // data could be xmlDoc, jsonObj, html, text, etc...
          // textStatus can be one of:
          // "timeout"
          // "error"
          // "notmodified"
          // "success"
          // "parsererror"
          // NOTE: Apparently, only "success" is returned when you make
          // an Ajax call in this way. Other errors silently fail.
          // See above note about using $.ajax.
          if (textStatus == "success") {
            $(a).toggleClass("selected");
          }
          var message = null;
          if ($(a).hasClass("selected")) {
			message = "GRAZIE. IL TUO VOTO E' STATO REGISTRATO&nbsp;&nbsp;";
          }
          else {
			message = "IL TUO VOTO E' STATO CANCELLATO";
          }
		  
          
          var m =$("#message_super");
          var o = m.offset(); // calcola posizione div
		  
		  var testo = '<div id="message_super"><div id="message">' + message  +'</div></div>';
		  //$("showcase_content").append(testo);
		  //$(m).fadeOut("normal").remove();

		  $("#toollike").append(testo);
          //setTimeout(function(){$(m).fadeOut("normal").remove()}, 3000);
		  setTimeout(function(){var m =$("#message_super"); $(m).fadeOut("normal").remove()}, 3000);
        });
    });
  $(".post-is-votable").click(function(event) {
    $("#toollike a").click();
    event.preventDefault();
  });
  $(".post-is-not-votable").click(function(event) {
    window.location.replace($("#loginLink").attr("href"));
  });
});