/* CONFIG */
var TT_on_object 		= ".tt";
var TT_margin_right 	= 0;
var TT_margin_bottom 	= 20;
var TT_margin_top 		= 14;

function TT_init(event) {
	/* create tt div */
    if (document.getElementById("tt") == null) {
        $("body").append('<div id="tt"></div>');
    }
    /* hide it */
    $('#tt').hide();
    /* onMouseOver */
    $(TT_on_object).mouseover(function(){
	      var t = this.title
	      if(!t) return false;
	      $(this).children().attr("title", "");
	      $('#tt').html(t);
	      $(this).removeAttr('title');
	      $('#tt').show();
	     // $('#tt').animate({opacity: 'toggle'}, "fast");
	      return true;
     });
    /* onMouseOut */
    $(TT_on_object).mouseout(function(){
	      $('#tt').hide();
	      $(this).attr('title', $('#tt').html());
	      $('#tt').html('');
	      return true;
     });
    /* Bind Events */
	$('body').bind('mousemove', TT_update)
}

function TT_update(event) {
		if(event && $('#tt').css('display')!='none') {
			var left = event.pageX + TT_margin_right;
			var top = event.pageY + TT_margin_bottom;
			//alert(top+' ? '+$(window).height()+' || '+$(window).scrollTop());

			if((top + $('#tt').height()) > ($(window).height() + $(window).scrollTop()))
			{
				top = event.pageY - ($('#tt').height() + TT_margin_top);
			}
			/* SET CSS */
			$('#tt').css({
				position: 'absolute',
				left: left + 'px',
				top: top + 'px'
			});
		}
}

$(document).ready(TT_init);