	function refresh_control_bar()//timed function for keeping the content in control bar fresh
		{
			//friends_tab();
		//	mail_events();
			//chat_tabs();
			populate_chat_room();
			var t= setTimeout("refresh_control_bar()",6000);
		}

		$(document).ready(function() 
		{
			refresh_control_bar();//launches the timing function
			
			$('#chat_room_tab').bind('keyup', function(e) {//binds the enter key to submit a message
				count_chars();
					if(e.keyCode==13){
			                send_chat_room_message();
			        }
			});
		});
		
		function count_chars()
		{
			var message = $("input#chat_room_message").val(); 
			var length = message.length;
			$('#chars_remaining').html("      You have " + (150-length) + " characters remaining");
		}
		function open_chat_room()
		{
			$.post("rtr_control.php",{start_chat_room_session : 1});
			populate_chat_room()
			$("#chat_room_tab").fadeIn();
		}
		
		function send_chat_room_message()
		{
			var username='{/literal}{$smarty.session.username}{literal}';
		 	var message = $("input#chat_room_message").val(); 
			$.post('rtr_control.php',{
				chat_room_message: message
				});
			$("input#chat_room_message").val("");
			$('#chars_remaining').html("");
			populate_chat_room();
		}
		
		function populate_chat_room()
		{
			$.get("rtr_control.php",{chat_room_session_exists:1}, function(data)
			{
				if (data > 0)//session exists
				{
					$("#chat_room_tab").fadeIn();
					$("#chat_room_messages").load("rtr_control.php",{chat_room_populate:1},function()
					{
						$("#chat_room_messages").scrollTo(100000);
					}
					);
				}
				else //fill the most recent message
				{
					$("#rtr_chat_room_last_message").load("rtr_control.php",{rtr_chat_room_last_message : 1});
				}
			}
			)


		}
		
		function close_chat_room()
		{
			$.post("rtr_control.php",{close_chat_room_session: 1});
			$("#chat_room_tab").fadeOut();
			//reset message index
		}

