function scroll(element){ 
	if (flag_scroll) {
		document.getElementById(element).scrollTop = document.getElementById(element).scrollHeight;
	}
}
function affiche(init)
{
	$.get('./tchat/read.php' + (init?'?INIT=1':''), function(data){
		$('#affichage').append(data);
		scroll('affichage');
	});

}
function ecrit(msg)
{
	$.get('./tchat/write.php?MSG='+msg);
}

$(document).ready(function(){
	
	$("#send").click(function(){
		if ($("#message").val()!='Votre message') {
			ecrit($("#message").val());
			$("#message").val('');
			$("#message").focus();
		}
	});
	
	$("#message").keypress(function(event){
		if (event.keyCode == '13') {
			$("#send").click();
		}
	});
	$("#message").click(function(){
		if ($(this).val()=='Votre message') {
			$(this).val('');
		}
	});
	
	flag_scroll=true;	
	$("#affichage").mouseover(function(){
		flag_scroll=false;
	}).mouseout(function(){
		flag_scroll=true;
	});
	
	$('#affichage .chargement').hide();
	
	affiche(true);
	setInterval("affiche();", 700);

});
