$(document).ready(function() {
	/* MODIFIED: http://briancray.com/2009/10/06/scroll-to-top-link-jquery-css/ */
	/* set variables locally for increased performance */

	var scroll_timer;
	var displayed = false;
	var $scrl = $('#scroll');
	var $window = $(window);
	var top = 170;
 
	/* react to scroll event on window */
	$window.scroll(function () {
		window.clearTimeout(scroll_timer);
		scroll_timer = window.setTimeout(function () { // use a timer for performance
			if($window.scrollTop() <= top) // hide if at the top of the page
			{
				displayed = false;
				$scrl.fadeOut(100);
			}
			else if(displayed == false) // show if scrolling down
			{
				displayed = true;
				$scrl.stop(true, true).fadeIn(100).click(function () { 
					$scrl.fadeOut(100);
					$('html,body').scrollTop(0);
					});
			}
		}, 100);
	});
	
});

