$(document).ready(function(){
	$(window).scroll(function() {
		if ($(this).scrollTop() > 542) { //set distance from top to start scrolling
			$("#chat").css({ "position": "fixed", "top": 40 }); //set distance from top for element when scrolling starts
		} else {
			$("#chat").css({ "position": "absolute", "top": "582px" }); //set default position of element
		}                           
	});
});
