function scTop(){
 $(".msgs").animate({scrollTop:$(".msgs")[0].scrollHeight});
}
function load_new_stuff(){
 localStorage['lpid']=$(".msgs .msg:last").attr("data-title");
 $(".msgs").load("pages/ajax.php?mod=getchat",function(){
  if(localStorage['lpid']!=$(".msgs .msg:last").attr("data-title")){
   scTop();
  }
 });
}
$(document).ready(function(){
 scTop();
 $("form#chatform").submit(function(){
  t=$(this);
  val=$("#chatform .form-control").val();
  if(val!=""){
   $.post("pages/ajax.php?mod=sendchat",{msg:val},function(){
    load_new_stuff();
    t[0].reset();
   });
  }
  return false;
 });
});
setInterval(function(){
 load_new_stuff();
},5000);
