	$(function(){
		var tooltipHolder = $(document.createElement("div")).appendTo('body');
		$(".hasTooltip").each(function() {
			$(this).tooltip({
				onBeforeShow: function() {
					$(".hasTooltip").each(function() {
						$(this).tooltip().getTip().hide();
					});
					
					var tooltipConfig = this.getConf();
					/*
					tooltipConfig['offset'] = [
						this.getTrigger().offset().top  - this.getTrigger().position().top,
						this.getTrigger().offset().left - this.getTrigger().position().left
					];
					*/
					if (this.getTrigger().offset().left - this.getTip().width()/2 < 0) {
						tooltipConfig['position'] = ['top', 'right'];
						this.getTip().addClass('tooltip-topRight');
					} else {
						tooltipConfig['position'] = ['top', 'center'];
						this.getTip().removeClass('tooltip-topRight');
					}
					
					if (this.getTip().parent().get(0) !== tooltipHolder.get(0)) {
						this.getTip().appendTo(tooltipHolder);
					}
				}
			});
		});
	});
