if (!Gipsyteam)
  var Gipsyteam = {};


Gipsyteam.Tooltip = (function(){
  var shown = false;

  var body, container, ieVersion;

  function init() {
    if (container)
      return;

    body = Builder.node('td', {style: 'position: relative; margin: 0px; padding: 0px; border-width: 0px; left: 0px; top: 0px; line-height: normal; width: auto; color: #333; font-size: 8pt; font-weight: normal; text-align: left;'});

    container = Builder.node('div', {style: 'position: absolute; overflow: hidden; padding: 0px; z-index: 1000;'}, [
      Builder.node('div', {style: 'position: relative; z-index: 0; top: 0px; border: 1px solid #666; background-color: #FFF; padding: 3px; text-align: left;'}, [
        Builder.node('table', {style: 'position: relative; margin: 0px; padding: 0px; border-width: 0px; left: 0px; top: 0px; line-height: normal; width: auto;'}, [
          Builder.node('tbody', {}, [
            Builder.node('tr', {}, [body])
          ])
        ])
      ])
    ]);

    document.body.appendChild(container);
    container.hide();
    document.observe('mousemove', onMouseMove);
  }

  function onMouseMove(ev) {
    if (!shown)
      return;

    var viewportOffset = document.viewport.getScrollOffsets();
    var viewportDims = document.viewport.getDimensions();
    var dims = body.getDimensions();

    var x = ev.clientX + 10 + viewportOffset.left;
    var y = ev.clientY + 25 + viewportOffset.top;

    if (x + dims.width > viewportDims.width + viewportOffset.left - 20) {
      x -= (x + dims.width) - (viewportDims.width + viewportOffset.left - 20);
    }
    x = Math.max(0, x);

    if (y + dims.height > viewportDims.height + viewportOffset.top && ev.clientY - 25 - dims.height > 0) {
      y = ev.clientY - 25 + viewportOffset.top - dims.height;
    }

    container.setStyle({top: y + 'px', left: x + 'px'})
  }

function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

  ieVersion = getInternetExplorerVersion();

  return {
    show: function(str) {
      if (ieVersion > 0 && ieVersion <= 7) return;
      if (/^\s*$/.test(str)) return;
      init();
      shown = true;
      body.update(str);
      container.show();
    },
    hide: function() {
      if (ieVersion > 0 && ieVersion <= 7) return;
      shown = false;
      if (body)
        body.update('');
      if (container)
        container.hide();
    }
  };
})();
