$(document).ready(function(e) {
	var objHat = $("#Hat");

	if ($(objHat).length > 0) {
		var HatWidth = $(objHat).width();

		function MoveHat(e) {
				var Pos = e.pageX - (HatWidth / 2);
				if (Pos < 0)
					Pos = 0;
				if (Pos + HatWidth > $(document).width())
					Pos = $(document).width() - HatWidth;
				$(objHat).css("left", Pos + "px");
		};

		$("body").bind("mousemove", MoveHat)
		e.pageX = $(document).width() / 2;
		MoveHat(e);
		
		$(objHat).bind("mousedown", function() {
				if ($(this).css("bottom") == "0px")
					$(this).css("bottom", "-50px");
				else
					$(this).css("bottom", "0px");
			});
	}
	
});
