function Tooltip (tips, type, fixed) {
   //this.tips = tips;
   this.type = type;
   this.fixed = fixed || false;
   this.active = false;
   this.id = 'tooltip-' + Tooltip.prototype.ids++;

   var el = YUKU.make_el('DIV', {id : this.id, className : 'tooltip', style : {
                                 position : 'absolute', display : 'none', zIndex : '10110'}
                                }, document.body);

   this.el = el;

   this.tips = {};
   for (var i in tips) {
      if (i.charAt(0) == '#') this.tips[(window.location.href + i)] = tips[i];
      else if (i.charAt(0) == '/') this.tips[('http://' + window.location.host + i)] = tips[i];
      else this.tips[i] = tips[i];
   }

   return this;
}

Tooltip.prototype = new ObjectEvents();
Tooltip.prototype.ids = 0;

Tooltip.prototype.init = function ()
{
   if (!this.fixed) // fluid
      this.addEvent(document, 'mousemove', 'mousemove');

   var links = YUKU.get_by_tag('A');

   for (var i = 0, l = links.length; i < l; i++) {
      if (this.tips[links[i].href]) {
         links[i].tooltip = this.tips[links[i].href];
         this.addEvent(links[i], 'mouseover', 'mouseover');
         this.addEvent(links[i], 'mouseout', 'mouseout');
      }
   }
}

Tooltip.prototype.mouseover = function (e) {
   this.active = true;
   var el = YUKU.get_target(e);
   if (!el.tooltip) return;
   this.el.innerHTML = el.tooltip;
   this.el.style.display = '';
   var pos = this.get_pos(e, el);
   this.el.style.left = pos.x + 'px';
   this.el.style.top = pos.y+ 'px';
}

Tooltip.prototype.mouseout = function (e) {
   this.active = false;
   this.el.innerHTML = '';
   this.el.style.display = 'none';
}

Tooltip.prototype.mousemove = function (e) {
   if (this.active) {
      var pos = this.get_pos(e, null);
      this.el.style.left = pos.x + 'px';
      this.el.style.top = pos.y + 'px';
   }
}

Tooltip.prototype.get_pos = function (e, el)
{
   var x, y = 0;
   var mouse = YUKU.find_mouse_xy(e);
   var coords = el ? YUKU.find_xy(el) : null;
   var doc = YUKU.doc_size();

   if (this.fixed)
   {
      if (this.type == 1) {  // nw
         x = coords.x;
         y = coords.y - this.el.offsetHeight - 2;

         if (x + 5 + this.el.offsetWidth > doc.x) x = doc.x - 5 - this.el.offsetWidth;
         if (y < 5) y = coords.y + el.offsetHeight + 2;
      }
      else if (this.type == 2) {  // n
         x = coords.x - ((this.el.offsetWidth - el.offsetWidth) / 2);
         y = coords.y - this.el.offsetHeight - 2;

         if (x + 5 + this.el.offsetWidth > doc.x) x = doc.x - 5 - this.el.offsetWidth;
         if (x < 5) x = 5;
         if (y < 5) y = coords.y + el.offsetHeight + 2;
      }
      else if (this.type == 3) {  // ne
         x = coords.x - (this.el.offsetWidth - el.offsetWidth);
         y = coords.y - this.el.offsetHeight - 2;

         if (x < 5) x = 5;
         if (y < 5) y = coords.y + el.offsetHeight + 2;
      }
      else if (this.type == 4) {  // se
         x = coords.x - (this.el.offsetWidth - el.offsetWidth);
         y = coords.y + el.offsetHeight + 2;

         if (x < 5) x = 5;
         if (y + 5 + this.el.offsetHeight > doc.y) y = coords.y - this.el.offsetHeight - 2;
      }
      else if (this.type == 5) {  // s
         x = coords.x - ((this.el.offsetWidth - el.offsetWidth) / 2);
         y = coords.y + el.offsetHeight + 2;

         if (x + 5 + this.el.offsetWidth > doc.x) x = doc.x - 5 - this.el.offsetWidth;
         if (x < 5) x = 5;
         if (y + 5 + this.el.offsetHeight > doc.y) y = coords.y - this.el.offsetHeight - 2;
      }
      else if (this.type == 6) {  // sw
         x = coords.x;
         y = coords.y + el.offsetHeight + 2;

         if (x + 5 + this.el.offsetWidth > doc.x) x = doc.x - 5 - this.el.offsetWidth;
         if (y + 5 + this.el.offsetHeight > doc.y) y = coords.y - this.el.offsetHeight - 2;
      }
   }
   else
   {
      if (this.type == 1) {  // nw
         x = mouse.x;
         y = mouse.y - this.el.offsetHeight - 2;

         if (x + 5 + this.el.offsetWidth > doc.x) x = doc.x - 5 - this.el.offsetWidth;
         if (y < 5) y = mouse.y + 15;
      }
      else if (this.type == 2) {  // n
         x = mouse.x - (this.el.offsetWidth / 2);
         y = mouse.y - this.el.offsetHeight - 2;

         if (x + 5 + this.el.offsetWidth > doc.x) x = doc.x - 5 - this.el.offsetWidth;
         if (x < 5) x = 5;
         if (y < 5) y = mouse.y + 15;
      }
      else if (this.type == 3) {  // ne
         x = mouse.x - this.el.offsetWidth;
         y = mouse.y - this.el.offsetHeight - 2;

         if (x < 5) x = 5;
         if (y < 5) y = mouse.y + 15;
      }
      else if (this.type == 4) {  // se
         x = mouse.x - this.el.offsetWidth - 5;
         y = mouse.y + 15;

         if (x < 5) x = 5;
         if (y + 5 + this.el.offsetHeight > doc.y) y = mouse.y - this.el.offsetHeight - 2;
      }
      else if (this.type == 5) {  // s
         x = mouse.x - (this.el.offsetWidth / 2);
         y = mouse.y + 15;

         if (x + 5 + this.el.offsetWidth > doc.x) x = doc.x - 5 - this.el.offsetWidth;
         if (x < 5) x = 5;
         if (y + 5 + this.el.offsetHeight > doc.y) y = mouse.y - this.el.offsetHeight - 2;
      }
      else if (this.type == 6) {  // sw
         x = mouse.x + 10;
         y = mouse.y + 15;

         if (x + 5 + this.el.offsetWidth > doc.x) x = doc.x - 5 - this.el.offsetWidth;
         if (y + 5 + this.el.offsetHeight > doc.y) y = mouse.y - this.el.offsetHeight - 2;
      }
   }

   return {x : x, y : y}
}