
   $(document).ready(function(){  
     timestamp = 0;  
	 
	 updateDefault();
     updateMsg();  
     $("form#chatform").submit(function(){  
       $.post("/includes/ajax/videochat.php",{  
             message: $("#msg").val(),  
             name: $("#author").val(),  
			 showid: $("#showid").val(),
             action: "postmsg",  
             time: timestamp  
           }, function(xml) {  
         $("#msg").empty();  
         addMessages(xml);  
       });  
       return false;  
     });  
	 
   });  
   function addMessages(xml) {  
     if($("status",xml).text() == "2") return;  
     timestamp = $("time",xml).text();  
     $("message",xml).each(function(id) {  
       message = $("message",xml).get(id);  
       $("#messagewindow").prepend("<b>"+$("author",message).text()+  
                     "</b>: "+$("text",message).text()+  
                     "<br />");  
     });  
	 $('#msg').val('');
	 toggleChat('on');
   }  
   function updateDefault(xml) {  
		$("#messagewindow").prepend("<b>TVGorge:</b>  Coming Soon!"); 
	
   }  
   function updateMsg() {  
      $.post("/includes/ajax/videochat.php",{  
			 showid: $("#showid").val(),
             time: timestamp  
           }, function(xml) {  
       $("#loading").remove();  
       addMessages(xml);  
     });  
    // setTimeout('updateMsg()', 4000);  
   }  
   
   
   
   
