/* 07.07.2010
 * popup comments v2.0
 * rev.11
 * by IonDen
 * UTF-8
 */

(function($){
	var screen_width = 0;
	var screen_scroll = 0;
	var help_width = 0;
	var help_height = 0;

	var help_cont = '';
	var help_offset = 0;
	var help_html = '';
	
	var hover_status = false;
	
	$(".car").live("mouseenter",function(){
		hover_status = true;

		screen_width = $("body").width();
		screen_scroll = $(window).scrollTop();
		
		help_cont = $(this).find("b").html();
		help_offset = $(this).offset();
		
		help_html = '<div id="helper_back"></div><div id="helper"><div id="helper_cont">';
		help_html += help_cont;
		help_html += '</div></div>';
		
		$("body").append(help_html);
		
		calc_size();
		
		$(this).bind("mouseleave",function(){
			$("#helper_back").css("top",-9999).remove();
			$("#helper").remove();
			hover_status = false;
		});
	});
	
	$(document).bind("mousemove",function(e){
		if(hover_status === true) {
			calc_size();
			
			var local_left = e.pageX + 20;
			var local_top = e.pageY - help_height - 15;
			
			if(local_left + help_width > screen_width - 20) {
				local_left = screen_width - 20 - help_width;
			}
			
			if(local_top < screen_scroll) {local_top = e.pageY + 20};
			
			$("#helper_back").css("left",local_left).css("top",local_top);
			$("#helper").css("left",local_left + 3).css("top",local_top + 3);
			$("#helper_cont").css("visibility","visible");
		}
	});
	
	function calc_size() {
		help_width = $("#helper").width();
		help_height = $("#helper").height();
		if(help_width > 300) {help_width = 300};
		$("#helper_back").width(help_width).height(help_height);
		$("#helper").width(help_width);
	}
})(jQuery);
