﻿
function initPopupMessage(popupId, popupWidth, popupHeight, showAnimated, animDuration, delayMsec, xTopOffset, xRightOffset) {

  setTimeout(function() {
    jQuery("#" + popupId).each(function(elementIndex, element) {
      var $popup = jQuery(element);
      $popup.addClass("visiblepopup");

      var windowCenterX = jQuery(window).width() / 2;
      var windowCenterY = jQuery(window).height() / 2;

      $popup.find("img").css("width", "0px").css("height", "0px");
      $popup.css("width", "0px").css("height", "0px").css("top", windowCenterY + "px").css("left", windowCenterX + "px").show();
      var popupLeft = (windowCenterX) - (popupWidth / 2);
      var popupTop = (windowCenterY) - (popupHeight / 2);

      if (!showAnimated) animDuration = 0;

      $popup.find("img").animate({
        width: popupWidth,
        height: popupHeight
      }, animDuration, 'easeOutBounce');

      $popup.animate({
        left: popupLeft,
        top: popupTop,
        width: popupWidth,
        height: popupHeight
      }, (animDuration > 10 ? animDuration - 10 : 0), 'easeOutBounce',
      function() {
        jQuery(this).find(".popupclose").text("X").css("font-size", "18px").css("left", (popupLeft + popupWidth - xRightOffset) + "px").css("top", (popupTop + xTopOffset) + "px").fadeIn(500);
      });

    });
  }, delayMsec);
};


function closePopup() {
    var $popup = jQuery(".visiblepopup");

    jQuery(".popupclose").hide();
  
    $popup.find("img").animate({
        width: 0,
        height: 0
      }, 500, 'easeOutCirc');

     $popup.animate({
        width: 0,
        height: 0
      }, 500, 'easeOutCirc',
       function() { jQuery(this).remove(); }
     );
}
