  var off_site_link;

$(document).ready(function(){
  function centerPopup(y_position){
    //request data for centering
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#tar_popup_wrapper").height();
    var popupWidth = $("#tar_popup_wrapper").width();

    //centering
    $("#tar_popup_wrapper").css({
      "position": "absolute",
      "top": y_position - 250,
      "left": windowWidth/2-popupWidth/2,
      "border": "1px black solid",
      "background-color": "white",
      "text-align": "right",
      "padding": "5px",
      "z-index": 999
    });

    $("#tar_popup").css({
      "background-color": "white",
      "margin": "5px",
      "padding": "5px",
      "font-size": "1.15em",
      "line-height": "1.5em",
      "text-align": "left"
    });
  }

  $("#close_tar").click(function () {
     $("#tar_popup_wrapper").hide();
     return false;
  });

  $("#tar_popup").click(function () {
     $("#tar_popup_wrapper").hide();
  });

  $(".offsite").click(function (e) {
    // source may be blank periodically ...
    var mouse_y_location = e.pageY;
    off_site_link = $(this).attr('href');
    var source = $(this).attr('title');
    centerPopup(mouse_y_location);
    $("#tar_popup").html("Fostering Connections would like to thank " + source + " for sharing this resource. Please click below to proceed to your selection.<br/><a href='" + off_site_link + "' target='_blank'><img src='/img/btn_click-to-continue.gif' style='display: block; margin-top: 10px; margin-left: auto; margin-right: auto;'/></a>");
    //$("#tar_popup").html("Fostering Connections would like to thank " + source + " for sharing this resource.");
    $("#tar_popup_wrapper").show();
    return false;
  });
});

