Creating my own plugin for automatic object positioning:
(function($){
$.fn.autoposition = function(ref, opt){
var _this = $(this);
var position = function(_tip, _ref, opt){
var o = $.extend({
"topallowance":0,
"leftallowance":0
}, o || opt);
var _window = $(window);
var _widthOfWindow = _window.width();
var _widthDifferenceFromXaxisOfRef = _widthOfWindow - _ref.offset().left;
var _xAdjustmentOftipWhenExceedAtLeftSide = ((_tip.outerWidth() > _widthDifferenceFromXaxisOfRef) ? (_tip.outerWidth() - _widthDifferenceFromXaxisOfRef) + o.leftallowance : 0);
var _leftOfTheTip = _ref.offset().left - _xAdjustmentOftipWhenExceedAtLeftSide;
var _heightOfWindow = _window.outerHeight();
var _heightDifferenceFromYaxisOfRef = _heightOfWindow - (_ref.offset().top + _ref.outerHeight());
var _topOfTheTip = (_tip.outerHeight() > _heightDifferenceFromYaxisOfRef) ? (_ref.offset().top - _tip.outerHeight()) - o.topallowance : (_heightOfWindow - _heightDifferenceFromYaxisOfRef) + o.topallowance;
_tip
.css('position', 'absolute')
.css('top', _topOfTheTip)
.css('left', _leftOfTheTip)
;
};
position(_this, ref, opt);
$(window).bind('resize', function(){
position(_this, ref, opt);
});
};
})(jQuery);
To implement it:
$(".TooltipSample").autoposition($(".theObjectWhereTheTooltipWillShow"));
Hopefully this will be useful to others.