//

function setToolTips(elem,b_dress_to_left,i_max_width) {

    if (i_max_width != undefined)
    {
      tooltip.setmaxwidth(i_max_width);
    }

    $(elem).each(
        function() {
            $(this).mouseover(
                function()
                {
                  if ($(this).attr('tip') != '')
                  {
                    tooltip.show($(this).attr('tip'), b_dress_to_left);
                  }
                })
            $(this).mouseout(
                function()
                {
                  if ($(this).attr('tip') != '')
                  {
                    tooltip.hide();
                  }
                })
        })
}


function clearToolTips(elem)
{
  tooltip.park();
  document.onmousemove = null;
}


var tooltip = function()
 {
   var tt, t, c, b, h, id, top, left, maxw, speed, timer, endalpha, alpha;

   var id       = 'tt';
   var top      = 1;
   var left     = 1;
   var maxw     = 400;
   var speed    = 5;
   var timer    = 10;
   var endalpha = 75;
   var alpha    = 0;
   var i_max_width = 0;
   var b_dress_to_left = 0;
 
   return {

    setmaxwidth: function(i_new_max_width) { i_max_width = i_new_max_width; }, 
    show: function(v,b,w)
          {
            b_dress_to_left = b;

            if (tt == null)
            {
              tt = document.createElement('div');
              tt.setAttribute('id', id);
              t = document.createElement('div');
              t.setAttribute('id', id + 'top');
              c = document.createElement('div');
              c.setAttribute('id', id + 'cont');
              b = document.createElement('div');
              b.setAttribute('id', id + 'bot');
              tt.appendChild(t);
              tt.appendChild(c);
              tt.appendChild(b);
              document.body.appendChild(tt);
              tt.style.opacity = 0;
              tt.style.filter = 'alpha(opacity=0)';
              $(document).bind("mousemove", this.pos);
            }
            tt.style.display = 'block';
            c.innerHTML = v;
            tt.style.width = w ? w + 'px' : 'auto';
            if (tt.offsetWidth > maxw)
            {
              tt.style.width = maxw + 'px';
            }
            h = parseInt(tt.offsetHeight) + top;
            if (tt.timer)
            {
              clearInterval(tt.timer);
            }
            tt.timer = setInterval(function(){tooltip.fade(1)},timer);
          },

    pos: function(e)
         {
           var u, l, c;

           if (!e)
           {
             return;
           }

           l = +e.pageX;
           u = +e.pageY;

           l -= $("div#ganz").position().left;
           u -= $("div#ganz").position().top;

           //if (i_max_width   > 0
           //    &&
           //    l + left - 10 > i_max_width / 2)
           //{

           if (b_dress_to_left)
           {
             l -= $(tt).width();
           }
           //}

           tt.style.top  = (u - h) + 'px';
           tt.style.left = (l + left) + 'px';
         },

    fade: function(d)
          {
            var i, a;

            a = alpha;
            if ((a != endalpha && d == 1) || (a != 0 && d == -1))
            {
              i = speed;
              if (endalpha - a < speed && d == 1)
              {
                i = endalpha - a;
              }
              else if (alpha < speed && d == -1)
              {
                i = a;
              }
              alpha = a + (i * d);
              tt.style.opacity = alpha * .01;
              tt.style.filter = 'alpha(opacity=' + alpha + ')';
            }
            else
            {
              clearInterval(tt.timer);
              if (d == -1)
              {
                tt.style.display = 'none'
              }
                                }
          },
  
    hide: function()
          {
            clearInterval(tt.timer);
            tt.timer = setInterval(function(){tooltip.fade(-1)}, timer);
          },

    park: function()
          {
            if (tt != null)
            {
              if (tt.timer != null)
              {
                clearInterval(tt.timer);
              }

              tt.style.display = 'none';
            }
          }
        };
}();

// eof (tooltip)

