jQuery(document).ready(function($)
{
	var username;
	
	function loadTwitterComments()
	{
		$.ajax(
		{
			type: "POST",
			url: $(".twitcomments .path").val() + "/js/ajax.php",
			data: "action=loadcomments",
			success: function(response)
			{
				$(".comments").html(response);
				//comment loaded
			}
		});
	}
	loadTwitterComments();
	
	$('.twitcomments input.submit').click(function()
	{
		$.ajax(
		{
			type: "POST",
			url: $(".twitcomments .path").val() + "/js/ajax.php",
			data: "action=login&username=" + $(".twitcomments .username").val() + "&password=" + $(".twitcomments .pass").val(),
			success: function(response)
			{
				if (response == "Basic authentication is not supported")
				{
					$(".twitcomments .message").html("");
					$(".twitcomments .login-module").css({'display': 'none'});
					$(".twitcomments .comment-module").css({'display': 'block'});
					username = $(".twitcomments .username").val();
				}
				else
				{
					$(".twitcomments .message").html("Incorrect Username/Password..");
				}
			}
		});
		return false;
	});
	
	$('.twitcomments input.submit-comment').click(function()
	{
		$.ajax(
		{
			type: "POST",
			url: $(".twitcomments .path").val() + "/js/ajax.php",
			data: "action=addcomment&username=" + username + "&comment=" + $(".twitcomments .comment").val(),
			success: function(response)
			{
				if (response == "updated")
				{
					loadTwitterComments();
				}
			}
		});
		return false;
	});
});
