$().mousemove(function (e){
    if (ToolObj != undefined)
    if (ToolObj.enabled !== null && ToolObj.enabled)
	{
	hei = $(ToolObj.reference).height();
	wid = $(ToolObj.reference).width();
	if (e.pageY + hei + 20 < $(document).height())
	    toy = e.pageY+10;
	else
	    toy = e.pageY-10-hei;
	if (e.pageX + wid + 30 < $(document).width())
	    tox = e.pageX+10;
	else
	    tox = e.pageX-10-wid;
	
	$(ToolObj.reference).css({left:(tox)+'px',top:(toy)+'px'});

	}
});
var ToolObj;
$(document).ready(function(){
ToolObj = new ToolTip();
//$('#menus li').each(function(){$(this).hover(function(){show_tip($(this).html());},function(){hide_tip();})});
});
function ToolTip()
    {
    this.construct();
    this.create_tooltip();
    }
ToolTip.prototype.construct = function()
    {
    this.default_ref_name = 'tooltip';
    this.reference;
    this.ref_obj_style = {};
    this.enabled = false;
    this.idstr = "";
    }
ToolTip.prototype.ajax_callback = function(ht,id_str)
    {
    if (id_str == undefined) id_str = "";
    if (this.idstr == id_str)
	$(this.reference).html(ht);
    }
ToolTip.prototype.show_tip = function(ht, id_str)
    {
    if (id_str == undefined) id_str = "";
    this.idstr = id_str;
//    alert(this.idstr);
    $(this.reference).html(ht);
    $(this.reference).show();
    this.enabled = true;
    }
ToolTip.prototype.show_by_ref = function(ref)
    {
    this.ref_obj_style = {};
    for (i in $(ref).get(0).style)
	{
	this.ref_obj_style = $(ref).get(0).style.cssText;
	}
    $(ref).css({position: 'absolute',zIndex: '100000'});
    this.reference = ref;
    $(this.reference).slideDown(100);
    this.enabled = true;
    this.enabled_temporary = true;
    }
ToolTip.prototype.hide = function(id_str)
    {
    if (id_str == undefined) id_str = "";
    if (this.idstr == id_str || id_str == ""){
    this.enabled = false;
    for (i in this.ref_obj_style)
	{
	$(this.reference).get(0).style.cssText = this.ref_obj_style;
	}
    $(this.reference).hide();}
    }
ToolTip.prototype.create_tooltip = function()
    {
//    for (i in this)
//	alert('['+i+']' +'> '+this[i]);
    if ($('#'+this.default_ref_name).size() == 0)
	{
	$('body').append("<div id='"+this.default_ref_name+"' style='position: absolute; display: none;' class='tool_tip_containter'></div>");
	}    
    this.reference = $('#'+this.default_ref_name);
    }

