title: How to position 400 x 400px popup div relative to click, keeping in screen view
body: <p>Preferably with jQuery since it's so much easier to understand.</p>
  
  <p>The following works great for horizontal.  The issue is vertical can be cut off on top requiring the user to scroll up to see the entire popup.</p>
  
  <pre><code>function pop_IT(X,event){
      dist_to_right_edge = $('body').innerWidth()-(x-$.scrollbarWidth());
      dist_to_bottom = $(window).height()-y;
      X=$('#'+X).get(0);
      X.style.left = 5+x+"px";
      X.style.top = 5+y+"px";
      if(dist_to_right_edge &lt; (X.offsetWidth+5)){X.style.left = x - X.offsetWidth-5+"px";}
      if(dist_to_bottom &lt; (X.offsetHeight+5)){X.style.top = y - X.offsetHeight-5+"px";}
      }
  </code></pre>
  
  <p>Then I load something like</p>
  
  <pre><code>$('#object').load('../whatever.php',function(event){pop_IT('object',event);});
  </code></pre>