/*************************************************************************
  
  dw_tooltip.js
  version date: jul 2010
  requires: dw_event.js and dw_viewport.js
  
  This code is from Dynamic Web Coding at http://www.dyn-web.com/
  Copyright 2003 by Sharon Paine 
  See Terms of Use at http://www.dyn-web.com/bus/terms.html
  regarding conditions under which you may use this code.
  This notice must be retained in the code as is!

*************************************************************************/

var Tooltip = {
  followMouse: true,
  offX: 8,
  offY: 12,
  
  ready: false,
  t1: null,
  t2: null,
//  tipID: "tipDiv",
  ifrm: null,
  tip: null,
  onloadGif :null,
  onload : false,
  opened: [false,false],
  
  init: function() {
    if ( document.createElement && document.body && typeof document.body.appendChild != "undefined" ) {
      this.tip = document.createElement("div");
      this.tip.id = "tipID";
      this.tip.className = "tooltiploc";
      document.body.appendChild(this.tip);
      this.tip = document.getElementById("tipID");
      
      this.onloadGif = document.createElement("div");
      this.onloadGif.id = "dict_loading";
      this.onloadGif.className = "dict_onload";
      document.body.appendChild(this.onloadGif);
      this.onloadGif = document.getElementById("dict_loading");
      this.onloadGif.innerHTML = '<img src="http://itszotar.hu/images/loading.gif" / border="0">';


      this.ifrm = document.createElement("iframe");
      this.ifrm.className = "tooltip";
      this.ifrm.style.border="0px";
      this.ifrm.style.visibility = 'hidden';
      document.body.appendChild(this.ifrm);
      this.ready = true;
    }
  },

  
  show: function(e, msg, loc) {
    if ( this.opened[0] || this.opened[1] ) return;
    if ( typeof loc == "undefined" ) 
      var loc = true;

      if ( loc )
      {
        this.opened[0] = true;
      } else
      {
        this.opened[1] = true; //this.ifrm;
        this.setonload(true);
      }
      if (this.t1) clearTimeout(this.t1);
      if (this.t2) clearTimeout(this.t2); 
      //this.tip = document.getElementById( this.tipID );
      // set up mousemove 
      if (this.followMouse) 
        dw_event.add( document, "mousemove", this.trackMouse, true );
      
      this.writeTip(msg, loc);
      viewport.getAll();
      this.positionTip(e);
      if (this.opened[0]) this.tip.style.display = 'inline';
    },
    
    writeTip: function(msg,loc) 
    {
      if ( this.opened[0] || this.opened[1] )
      {
        if ( ! loc && this.opened[1] ) 
        {
          this.ifrm.setAttribute("src", msg+"&host="+location.href.substr(7, location.href.indexOf('/',7)-7));
        } else 
        {
          this.tip.innerHTML = msg;
        }
      }
    },
    
    positionTip: function(e) {
      if ( ! this.opened[0] && !this.opened[1] ) return;
      var change = (this.opened[0]? this.tip : this.ifrm);
      var x = e.pageX? e.pageX: e.clientX + viewport.scrollX;
      var y = e.pageY? e.pageY: e.clientY + viewport.scrollY;
      if (this.onload)
      {
        this.onloadGif.style.left = x+"px"; this.onloadGif.style.top = y+"px"; 
      }
      if ( x + change.offsetWidth + this.offX > viewport.width + viewport.scrollX )
        x = x - change.offsetWidth - this.offX;
      else x = x + this.offX;
    
      if ( y + change.offsetHeight + this.offY > viewport.height + viewport.scrollY )
        y = ( y - change.offsetHeight - this.offY > viewport.scrollY )? y - change.offsetHeight - this.offY : viewport.height + viewport.scrollY - change.offsetHeight;
      else y = y + this.offY;
  
      change.style.left = x + "px"; change.style.top = y + "px";
    },
    
    hide: function() {
      this.setonload(false);
      if ( this.opened[0] ) this.tip.style.display = 'none';
      if ( this.opened[1] ) this.ifrm.style.visibility = 'hidden';
      this.opened[0] = false;
      this.opened[1] = false;

      // release mousemove
      if (this.followMouse) 
        dw_event.remove( document, "mousemove", this.trackMouse, true );
    },
    
    trackMouse: function(e) {
      return;
      e = dw_event.DOMit(e);
      Tooltip.positionTip(e);    
    },
    
    setSize: function(size)
    {
      if ( ! this.opened[1] ) return;
      this.ifrm.height = size;
      this.ifrm.style.visibility = 'visible';
      this.setonload(false);

    },
    
    setonload: function(h)
    {
      this.onloadGif.style.display = h ?'inline':'none';
      this.onload = h;
    }

}

function doTooltip(e, msg) {
  if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
  Tooltip.show(e, msg,true);
}

function doTooltipHref(e, url) {
  if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
  Tooltip.show(e, url,false);
}
            
function hideTip() {
  if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
  Tooltip.hide();
}


Tooltip.init();
