var tooltip=function(){
  var id = 'tt';
  var top = 3;
  var left = 3;
  var maxw = 300;
  var alpha = 95;
  var tt,t,c,b,h;
  var ie = document.all ? true : false;
  return{
    show:function(v,w){
      if(tt == null){
        tt = document.createElement('div');
        tt.setAttribute('id',id);
        c = document.createElement('div');
        c.setAttribute('id',id + 'cont');
        tt.appendChild(c);
        document.body.appendChild(tt);
        tt.style.opacity = alpha;
        tt.style.filter = 'alpha(opacity=' + alpha + ')';
        document.onmouseover = this.pos;
      }
      tt.style.display = 'block';
      c.innerHTML = v;
      tt.style.width = w ? w + 'px' : 'auto';
      if(!w && ie){
        tt.style.width = tt.offsetWidth;
      }
      if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
      h = parseInt(tt.offsetHeight) + top;
    },
    pos:function(e){
      var width = tt.offsetWidth;
      var height = tt.offsetHeight;
      var epgx = (event.pageX ? event.pageX : event.clientX + document.body.scrollLeft);
      var epgy = (event.pageY ? event.pageY : event.clientY + document.body.scrollTop);

      if (epgx - width - 50 + document.body.scrollLeft >= 0 ) {
        tt.style.left = (epgx - width - 20) + 'px';
      } else {
        tt.style.left = (epgx + 20) + 'px';
      }


      if (epgy - height - 50 + document.body.scrollTop >= 0) {
        tt.style.top = (epgy - height - 20) + 'px';
      } else {
        tt.style.top = (epgy + 20) + 'px';
      }
    },
    hide:function(){
      tt.style.display = 'none';
    }
  };
}();
