// The "Close" button in the twitter update form at the top of the page
// works differently to that in all other TwitterUpdateWidgets.
// We make it work here.
// Assumes the form has id "update-twitter-form".
$(function() {
	$('#update-twitter-form .close-panel').click(function() {
		$('#update-twitter-form').slideUp('slow');
		return false;
	});
	$('#update-twitter-form .TwitterUpdateWidget :submit').click(function() {
		$('#update-twitter-form').slideUp('slow');
		$(this).parents('form').ajaxSubmit(function(response) {
			var json = response; //eval("(" + response + ")");
			if (!json['success']) {
				alert(json['error']);
			} else {
				//reload on own profile post
				var url = ""+window.location;
				if (url.slice(-8) == "/profile") {
					window.location.reload();
					return;
				}
				// TODO clear form				
			}
		});
		return false;
	});
});
