$(document).ready(
function()
{
// Starts the callback cycle.
function listenForCallback(callbackId){

$.get
(
	"callback.php",
	{id_no: callbackId},
	function(data)
	{
		$data = data.replace(/ /,'');
		switch($data.substring(2,0))
		{
			case "r:":
				listenForCallback(callbackId);
			break;
			case "u:":
				updateContents();
				listenForCallback($data.split(":")[1]);
			break;
			default:
				listenForCallback(callbackId);
			break;
		}
	}
);
}

// Updates the contents of the box when called.
function updateContents(){
	
	$.post("output.php","",function(data){
		$("#text").html(data);
		// Makes sure all links open in the TOP window/frame.
		$("a").attr('target', '_top');

		$("a").filter(function() {
					return this.hostname && this.hostname !== location.hostname;
		}).css('font-style', 'italic');

	},
	'html');
}

// Handles form submission.
$("#shout").submit(function(){

	$.post(
		"post.php",
		$("#shout").serialize(),
				
			function(data){

				if(!data == ""){alert("An error has occured:" + data);}

			},

		"html");
	$("#txtMsg").val('');
	return false;
});

updateContents();
listenForCallback(-1);

});