﻿$(function() {
	var activatePopup = "img.display_popup";
	var thisPopup = "div.popup";

	$(thisPopup).hide();
	// $(thisPopup).ifixpng()

	$(".callout-reviews li").each(function() {
		var distance = 5;
		var time = 250;
		var hideDelay = 0;
		var hideDelayTimer = null;
		var beingShown = false;
		var shown = false;
		var trigger = $(activatePopup, this);
		var popup = $(thisPopup, this).hide();

		$([trigger.get(0), popup.get(0)]).mouseover(function() {
			// Stops the hide event if we move from the trigger to the popup element
			if (hideDelayTimer) {
				clearTimeout(hideDelayTimer);
			}

			// Don't trigger the animation if we're being shown
			if (beingShown || shown) {
				return;
			}
			else {
				beingShown = true;
			}

			// Reset position of popup
			popup.css({
				top: -325,
				left: 15,
				display: "block"
			});

			popup.show();
			beingShown = false;
			shown = true;

		}).mouseout(function() {
			if (hideDelayTimer) {
				clearTimeout(hideDelayTimer);
			}

			hideDelayTimer = setTimeout(function() {
				hideDelayTimer = null;

				popup.hide();
				shown = false;

			}, hideDelay);
		});
	});
});