/* 15.03.2010
 * popup commentws v1.0
 * rev.5
 * by IonDen
 * UTF-8
 */

$(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").parent("A").hover(function() {
		$(this).css( "cursor", "help" );
		var tth = $(this);
		var th = $(this).children("span");
		$(th).addClass("cHelp");
		helpContent = $(th).attr("help");
		helpOffset = $(th).offset();
		$("body").append('<div id="helperBord"></div><div id="helperBack"></div><div id="helper">'+helpContent+'</div>');
		helpWidth = $("#helper").outerWidth();
		if(helpWidth > 300) {helpWidth = 300};
		
		$("#helperBord").width(helpWidth-2);
		$("#helperBack").width(helpWidth);
		$("#helper").width(helpWidth);
		helpHeight = $("#helper").innerHeight();
		$("#helperBord").height(helpHeight-5);
		$("#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 - 50) {helpX = screenWidth - 50 - helpWidth*2};
			//helpY = helpY - helpHeight;
			
			var offset = $(tth).offset();
			helpX = offset.left - $("#helperBord").width() - 57;
			helpY = offset.top;
			
			if(helpY < screenScroll + 15) {helpY = e.pageY + 15};
			
			$("#helperBord").css("left",helpX + 30).css("top",helpY);
			$("#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 = "";
			$("#helperBord").remove();
			$("#helperBack").remove();
			$("#helper").remove();
		});
		*/
	},
	function()
	{
		$(".cHelp").removeClass("cHelp");
		helpWidth = 0;
		helpHeight = 0;
		helpContent = "";
		$("#helperBord").remove();
		$("#helperBack").remove();
		$("#helper").remove();

	});
});
