$(document).ready(function () {
	$('.bubbleInfo').each(function () {
		var distance = 10;
		var time = 250;
		var hideDelay = 250;
		
		var hideDelayTimer = null;
		var beingShown = false;
		var visible = false;
		
		var trigger = $(this);
		var popup = $('.popup', this);
		
		$([trigger.get(0), popup.get(0)]).mouseover(function() {
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			
			if (beingShown || visible) {
				return;
			} else {
				beingShown = true;
				popup.css({
					display: 'block',
					top: -50,
					left: 150
				}).animate({
					opacity: 1,
					top: '-=' + distance + 'px'
				}, '', function () {
					beingShown = false;
					visible = true;
				});
			}
		}).mouseout(function () {
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			
			hideDelayTimer = setTimeout(function () {
				hideDelayTimer = null;
				popup.animate({
					top: '-=' + distance + 'px',
					opacity: 0
				}, '', function () {
					visible = false;
				});
			}, hideDelay);
		});
	});
});
