jQuery(document).ready(

	function(){
		//check to see if we have a session
	jQuery('.send').click(
	function()
		{ sendMsg(); }
	);
	
	jQuery('.txt').keypress(function(e){
		if (e.which == 13){
			sendMsg();
		}
	}); 
	
	jQuery('#login').click(function(){
		num = Math.random();
		jQuery.post('/chat.php?func=login&'+num, {username: jQuery('#uname').attr("value"), password:jQuery('#password').attr("value")},
		function(data){
			if(data.status=="online"){
				jQuery('.container').data("online", true);
				jQuery('.inputPane').show('slow');
				jQuery('#logout').show();
				jQuery('#loginform').hide();
			}else{
				jQuery('.container').data("online", false);
				jQuery('.inputPane').hide('slow');
				jQuery('#logout').hide();
			}
		}, "json");
	});

	jQuery('#logout').click(
	function(){
		jQuery.post("/chat.php?func=logout");
		jQuery('.inputPane').hide('slow');
		jQuery('#logout').hide();
		jQuery('#loginform').show();
		}
	);
	
	checkSession();
	updateChat();
	updateUsers();

});


function removePost(post) {
	jQuery.post("/chat.php?func=remove&post=" + post);
}

	
function checkSession(){
	jQuery.post('/chat.php?func=check', {},
	function(data){
			if(data.status=="online"){
				jQuery('.container').data("online", true);
				jQuery('#loginform').hide();
				jQuery('.inputPane').show('slow');
				jQuery('#logout').show();
			}else{
				jQuery('.container').data("online", false);
				jQuery('.inputPane').hide();
				jQuery('#logout').hide();
				}
		}, "json");
}

function updateChat() {
	 num = Math.random();
	jQuery('.messages').load('/chat.php?func=get&'+num);   
	setTimeout('updateChat()', 1000);       
}

function updateUsers(){
	num = Math.random();
	jQuery('.online').load('/chat.php?func=online&'+num);
	setTimeout('updateUsers()', 10000);  
}

function sendMsg(){
		  mymessage   =  jQuery('.txt').attr("value");
		  jQuery.post('/chat.php?func=send', {message: mymessage});
		  jQuery('.txt').attr("value", "");
		  return false;
	}
