jQuery: Adjust tooltip position if it goes below viewport?
<p>I have the following code that displays a tooltip by fetching the content via aJax, works great.</p>

<p>It also positions itself to the right of the tooltip...my problem now is...it goes below the viewport on some of th elonger tooltips... can someone provide an example using my code below on how to check if the tooltip goes below the viewpoint, and if so, show it above it ?</p>

<pre><code>jQuery(document).ready(function(){
    jQuery('.tooltip').hover(function(){
    var offset = jQuery(this).offset();
    console.log(offset)
    var width = jQuery(this).outerWidth();
    var tooltipId = jQuery(this).attr("rel");
         jQuery('#tooltip-container').empty().load('tooltips.html ' + tooltipId).fadeIn(500);
         jQuery('#tooltip-container').css({top:offset.top, left:offset.left + width + 10}).show();
    }, function(){
        jQuery('#tooltip-container').stop(true, true).fadeOut(500);
});
    });
</code></pre>
