$(document).ready(function(){
	$("#update_s").click(function(){
		$("#s_button").show('slow');
		$(this).empty().css('height',100);
	});

	$("#tweets, #info ").click(function(){
		$("#s_button").hide('slow');
		$("#update_s").css('height',20);
	});

	$('#update_s').keyup(function(){
		limitChars('update_s', 1000, 'counter');
	})

	$("#tweet_b").click(function(){
			msg = $("#update_s").val();
			if (msg.length == 0){
				alert("هیچی؟");
				return 0;
			}

			if (msg.length > 1000){
				alert("زیاده");
				return 0;
			}

			$.post("/profile/tweets/submit/",{ message: msg }, function(data){
				$("#tweets").prepend("<div class='message rc-small'><img src='/site_media/images/check.png' width='30'/>ok</div>");
				$("#s_button").hide('slow');
				$("#update_s").val("").css('height',20);
				
		}, 'json');
	});

	$("li.rate").click(function(){
		var id = get_id($(this).attr('id'));
		if ($(this).attr('id').search('m'))
			var action = 1;
		else
			var action = 0;

		$.post("/profile/tweets/rate/",{ action :action, t_id :id }, function(data){	
			if (data == "/accounts/signin/")
			{	
				p = window.location.pathname;
				window.location = "/accounts/signin/?next=" + p;
				return;
			}
			if (data == "duplicate")
			{
				$("#s_" + id).empty();
				$("#d_" + id).css("display", "block");
			}
			else if (data == "Error")
			{
				$("#s_" + id).empty();
				$("#e_" + id).css("display", "block");
			}
			else 
				$("#s_" + id).html(data);
		});
	});

	$(".delete").click(function(){
		var id = get_id($(this).attr('id'));
		$.post("/profile/tweets/delete/",{ t_id: id }, function(data){	
			if (data == "ok")
				$("#tweet-container_" + id).hide('slow');	
		});

	});

	
	
});
