/*************************************************************************
  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 Tooltip = {

             followMouse: false,
             offX: 8,
             offY: 12,
             tipID: "tipDiv",
             arrID: "arrDiv",
             showDelay: 1,
             hideDelay: 100,
             showDelayAjax : 10,
             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";
                      el1.style.top = "0";
                      el1.style.left = "0";
                      el1.style.zindex = 100;
                      document.body.appendChild(el1);
                   }
                   if(!document.getElementById(this.arrID)){
                      var el2=document.createElement("DIV");
                      el2.id=this.arrID;
                      el2.style.position = "absolute";
                      el2.style.top = "0";
                      el2.style.left = "0";
                      el2.style.zindex = 100;
                      document.body.appendChild(el2);
                   }
                   this.ready=true;
                   this.list_bool = new Array();
                   this.list_html = new Array();
                }
             },
             show:function(e,msg,modde){
                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(this.sender.id.indexOf('_'),this.sender.length);
                this.last_sender=sender;
                /*alert(this.writeTip(e, msg, modde));*/
                if (this.writeTip(e, msg, modde)) {
                 this.positionTip(e, msg, modde);
                 this.timer=setTimeout("Tooltip.toggleVis('"+this.tipID+"', 'visible');Tooltip.toggleVis('"+this.arrID+"', 'visible')",this.showDelay);
                } 
             }
             ,writeTip:function(e,msg,modde){
               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;
               }


               if (this.list_bool[msg.substring(msg.indexOf('_'),msg.length)]) {
                if(this.tip&&typeof this.tip.innerHTML!="undefined")
                  this.tip.innerHTML=this.list_html[msg.substring(msg.indexOf('_'),msg.length)];
                  return true;

               } else {
                  xajax_call_ajax('get_movie_description',msg, modde);
                  return false;
               }
             },
             ajaxResponse:function(msg){
                    if (this.tip && this.last_sender && this.last_sender.id == msg) {
                      this.list_bool[msg.substring(msg.indexOf('_'),msg.length)] = true;
                      this.list_html[msg.substring(msg.indexOf('_'),msg.length)] = this.tip.innerHTML;
                      this.positionTip(null, msg);
                      this.timer=setTimeout("Tooltip.toggleVis('"+this.tipID+"', 'visible');Tooltip.toggleVis('"+this.arrID+"', 'visible')",this.showDelayAjax);
                    }
             }
             ,positionTip:function(e, msg, modde){
                if(this.tip&&this.tip.style){
                  
                   position.init(msg, this.tipID);
                   if (this.sender.tagName == 'A') {
                     position.compareA(this.x, this.y);
                   } else if (msg.indexOf('showid') > -1) { 
                     position.compare_exp();
                   } 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, modde) {
  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, modde);
}

function hideTip() {
  if ( typeof Tooltip == "undefined" || !Tooltip.ready ) return;
  Tooltip.timerId = setTimeout("Tooltip.hide()", 300);
}

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(typeof(dw_event) != 'undefined') dw_event.add(window, "unload", Tooltip.unHookHover, true);

