
$(document).ready(function(){
	var helpContent = "";
	var helpOffset = 0;
	var helpWidth = 0;
	var helpHeight = 0;
	var helpX = 0;
	var helpY = 0;
	var screenWidth = 0;
	var screenScroll = 0;
	
	$(".helpme").mouseenter(function() {
		$(this).addClass("cHelp");
		helpContent = $(this).attr("help");
		helpOffset = $(this).offset();
		$("body").append('<div id="helperBack"></div><div id="helper"><div id="helpCont">'+helpContent+'</div></div>');
		helpWidth = $("#helper").outerWidth();
		if(helpWidth > 270) {helpWidth = 270};
		
		$("#helperBack").width(helpWidth);
		$("#helper").width(helpWidth);
		helpHeight = $("#helper").innerHeight();
		$("#helperBack").height(helpHeight-3);
		
        screenScroll = $(window).scrollTop();
        screenWidth = $("body").innerWidth();
		
		$(document).bind("mousemove",function(e){
			helpX = e.pageX;
			helpY = e.pageY;
			if(helpX + helpWidth > screenWidth - 60) {helpX = screenWidth - 60 - helpWidth};
			
			helpY = helpY - helpHeight - 10;
			if(helpY < screenScroll + 15) {helpY = e.pageY + 15};
			
			$("#helperBack").css("left",helpX + 32).css("top",helpY + 2);
			$("#helper").css("left",helpX + 32).css("top",helpY);
		});
		
		$(".cHelp").mouseleave(function() {
			$(this).removeClass("cHelp");
			helpWidth = 0;
			helpHeight = 0;
			helpContent = "";
			$("#helperBack").remove();
			$("#helper").remove();
		});
	});
});
