$("a.btn.vote").click( function () {
  if ($(this).hasClass("ignore_ajax")) {
    return
  }
  
  var $that = $(this);
  
  $that.addClass("activated");
  $("span.wrapper", $that).animate({
    opacity: 0.001
  }, 150);
  $.ajax({
	type: "POST",
    url: $that.attr('href'),
    success: function(data) {
      $("span.wrapper", $that).animate({
        opacity: 1
      }, 150);
      var button = $("span:not(span.val)", $that);
      button.unwrap();
      button.wrap("<div class='vote-btn activated'></div>");
      
      var voteCount = parseInt($("span.val", $that).text());
      $("span.val", $that).text(++voteCount);
      
    },
    error: function(data) {
      var voteCount = parseInt($("span.val", $that).html());
      $("span.val", $that).show().html(++voteCount);
      
      $("span.wrapper", $that).text(" Favourites").prepend(voteCount).animate({
        opacity: 1
      }, 150);
      var button = $("span:not(span.val, span.wrapper)", $that);
      button.unwrap();
      button.wrap("<div class='btn vote activated'></div>");
    }
  });

  return false
});

$(".admin-buttons a").click(function (event) {
  var $that = $(this);
  var $thatColor = $that.css('color');
  var finalText = "Complete";
  var removeElem = "none";
  
  if($that.text() === "Approve") {
    finalText = "Approved";
    removeElem = "reject";
  } else if ($that.text() === "Reject") {
    finalText = "Rejected";
    removeElem = "approve";
  } else {
    return true;
  };
  
  $that.animate({
    color: "#d5d5d5"
  }, 150);
  
  $.ajax({
    url: $that.attr('href'),
    success: function(data) {
      $that.animate({
        color: $thatColor
      }, 150);
      $that.text(finalText);
      $("." + removeElem, $that.parent()).fadeOut();
    },
    error: function(data) {

    }
  });
  
  return false;
});

