$(document).ready(function(){
  
	$('form.submit_suggestion').live('submit', function() {
	  $.post($(this).attr('action'), $(this).serialize(),
  		function(data) {
			  if (data != "") {
				  $('#suggestions .nosug').remove();
				  $('#suggestions, #submit_suggestion').toggle();
					$('#suggestions .category_list').append(data);
					if ($('#mask:visible')[0]) {
					  window.location.reload();
					}				
				}
			}
		);
	  return false;
	});
	
	$('.vote_count img', '#content').live('click', function() {
	  var $this = $(this);
	  $.post($(this).parent('form').attr('action'), $(this).parent('form').serialize(),
  		function(data) {
			  if (data.indexOf("|") != -1) {
					var str = data.split("|");
					$('#votes_'+str[0]).fadeOut(function() {
					  $(this).html(str[1]).fadeIn();
					});
				} else {
				  alert(data);
				}
			}
		);
	  return false;
	});

	$('.delete_text', '#content').live('click', function() {
	  if (confirm('Do you want to delete this suggestion?')) {
	    var $this = $(this);
	    $.post($(this).parent('form').attr('action'), $(this).parent('form').serialize(),
  		  function(data) {
			    if (data.indexOf("|") != -1) {
					  var str = data.split("|");
					  $('#item_'+str[0]).fadeOut();
				  } else {
				    alert(data);
				  }
			  }
		  );
		}
	  return false;
	});	
	
});
