/*************************************************************************
  dw_tooltip.js   requires: dw_event.js and dw_viewport.js
  version date: May 21, 2005 moved init call to body onload
  (March 14, 2005: minor changes in position algorithm and timer mechanism)
  
  This code is from Dynamic Web Coding at dyn-web.com
  Copyright 2003-5 by Sharon Paine 
  See Terms of Use at 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 var_show;
var Tooltip = {

             followMouse: false,
             offX: 8,
             offY: 12,
             tipID: "tipDiv",
             arrID: "arrDiv",
             showDelay: 100,
             hideDelay: 1000,
             ready:false,
             timer:null,
             tip:null,
             arr:null,
             list_bool:null,
             list_html:null,
             ttready:true,
             sender:null,
             last_sender:null,

             init:function(){
                if(document.createElement&&document.body&&typeof document.body.appendChild!="undefined"){
                   if(!document.getElementById(this.tipID)){
                      var el1=document.createElement("DIV");
                      el1.id=this.tipID;
                      el1.style.position = "absolute";
                      document.body.appendChild(el1);
                   }
                   if(!document.getElementById(this.arrID)){
                      var el2=document.createElement("DIV");
                      el2.id=this.arrID;
                      el2.style.position = "absolute";
                      document.body.appendChild(el2);
                   }
                   this.ready=true;
                   this.list_bool = new Array();
                   this.list_html = new Array();
                }
             },
             show:function(e,msg){
               if(this.timer){
                   clearTimeout(this.timer);
                   this.timer=0;
                }
                
                if (!this.ttready)  return;
                var sender = document.getElementById(msg);

                if (sender == this.sender) return;

                this.tip=document.getElementById(this.tipID);
                this.arr=document.getElementById(this.arrID);
                this.sender=sender;
                this.sender_id = this.sender.id.substring(0,this.sender.id.indexOf('_'));
                this.last_sender=sender;
                if (this.writeTip(e, msg)) {
                 this.positionTip(e, msg);
                 this.timer=setTimeout("Tooltip.toggleVis('"+this.tipID+"', 'visible');Tooltip.toggleVis('"+this.arrID+"', 'visible')",this.showDelay);
                } 
             }
             ,writeTip:function(e,msg){
               if (this.sender.tagName == 'A') {
                  viewport.getAll();
                  this.x = e.pageX?e.pageX:e.clientX+viewport.scrollX;
                  this.y = e.pageY?e.pageY:e.clientY+viewport.scrollY;
               }
               this.list_bool[msg.substring(0,msg.indexOf('_'))] = 1;    
               this.list_html[msg.substring(0,msg.indexOf('_'))] = eval("var_"+msg);

               if (this.list_bool[msg.substring(0,msg.indexOf('_'))]) {
                if(this.tip&&typeof this.tip.innerHTML!="undefined")
                  this.tip.innerHTML=this.list_html[msg.substring(0,msg.indexOf('_'))];
                  return true;
               }
             }
             ,positionTip:function(e, msg){
                if(this.tip&&this.tip.style){
                  
                   position.init(msg, this.tipID);
                   if (this.sender.tagName == 'A') {
                     position.compareA(this.x, this.y);
                   } else {
                     position.compare();
                   }
                   this.arr.innerHTML = "<img src='images/" + position.image_name + "'>";
                   this.arr.style.left = position.arrX+"px";
                   this.arr.style.top =  position.arrY+"px";
                   this.tip.style.left = position.tipX +"px";
                   this.tip.style.top =  position.tipY +"px";
                }
             }
             ,hide:function(){

                if(this.timer){
                   clearTimeout(this.timer);
                   this.timer=0;
                }
                this.timer=setTimeout("Tooltip.toggleVis('"+this.tipID+"', 'hidden'); Tooltip.toggleVis('"+this.arrID+"', 'hidden');",this.hideDelay);
                this.tip=null;
                this.arr=null;
                this.sender=null;
             }
             ,toggleVis:function(id,vis){
                var el=document.getElementById(id);
                if(el)el.style.visibility=vis;
             }
             ,trackMouse:function(e){
                e=dw_event.DOMit(e);
                Tooltip.positionTip(e);
             }
             ,hideImmediately:function(){
                eval("Tooltip.toggleVis('"+Tooltip.tipID+"', 'hidden'); Tooltip.toggleVis('"+Tooltip.arrID+"', 'hidden');");
             }

};

function doTooltip(e, msg) {
  if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
  Tooltip.clearTimer();
  var tip = document.getElementById? document.getElementById(Tooltip.tipID): null;
  if ( tip && tip.onmouseout == null ) {
  //      tip.onmouseout = Tooltip.tipOutCheck1;
      tip.onmouseout = hideTip;
      tip.onmouseover = Tooltip.clearTimer;
      tip.onclick = Tooltip.hideImmediately;

  }
  var arr = document.getElementById? document.getElementById(Tooltip.arrID): null;
  if ( arr && arr.onmouseout == null ) {
      //arr.onmouseout = Tooltip.tipOutCheck;
      arr.onmouseout = hideTip;
      arr.onmouseover = Tooltip.clearTimer;
      arr.onclick = Tooltip.hideImmediately;
  }
  Tooltip.show(e, msg);
}
/*
function doTooltip(e, msg) {

  if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
  Tooltip.clearTimer();

  var tip = document.getElementById? document.getElementById(Tooltip.tipID): null;
  if ( tip && tip.onmouseout == null ) {
      tip.onmouseout = Tooltip.tipOutCheck;
      tip.onmouseover = Tooltip.clearTimer;
  }
  var arr = document.getElementById? document.getElementById(Tooltip.arrID): null;
  if ( arr && arr.onmouseout == null ) {
      arr.onmouseout = Tooltip.tipOutCheck;
      arr.onmouseover = Tooltip.clearTimer;
  }

  Tooltip.show(e, msg);
}
  */
function hideTip() {
  if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
  Tooltip.timerId = setTimeout("Tooltip.hide()", 300);
}

Tooltip.tipOutCheck = function(e) {
  e = dw_event.DOMit(e);
  // is element moused into contained by tooltip?
  var toEl = e.relatedTarget? e.relatedTarget: e.toElement;
  if (this != toEl && !contained(toEl, this) && Tooltip.sender != toEl) {
    Tooltip.hide(); 
  } else {
//       dw_event.remove(Tooltip.sender)
  }
}

// returns true of oNode is contained by oCont (container)
function contained(oNode, oCont) {
  if (!oNode) return; // in case alt-tab away while hovering (prevent error)
  while ( oNode = oNode.parentNode ) if ( oNode == oCont ) return true;
  return false;
}

Tooltip.timerId = 0;
Tooltip.clearTimer = function() {
  if (Tooltip.timerId) { clearTimeout(Tooltip.timerId); Tooltip.timerId = 0; }
}

Tooltip.unHookHover = function () {
    var tip = document.getElementById? document.getElementById(Tooltip.tipID): null;
    if (tip) {
        tip.onmouseover = null; 
        tip.onmouseout = null;
        tip = null;
    }
}
if (var_show){
    dw_event.add(window, "unload", Tooltip.unHookHover, true);
}

