/*************************************************************************
  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 Tooltip1 = {
             followMouse: false,
             offX: 8,
             offY: 12,
             tipID: "tipDiv1",
             arrID: "arrDiv1",
             showDelay: 100,
             hideDelay: 200,
             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();
                   this.list_bool["whatthis"] = true;
                   this.list_html["whatthis"] = '<table border="0" cellpadding="0" cellspacing="0" width="325"><tbody><tr><td border="0" class="black" align="center" background="images/gt_top1.gif" height="26" valign="middle" width="325"><b>AVERAGE SCORE</b></td></tr><tr><td border="0" class="black" align="left" background="images/gt_mid1.gif" valign="middle" width="100%"><table width="100%" border="0"><tr><td width="100%" class="black"><img src="images/tran.gif" height="1"></td></tr></table></tr><tr>     <td border="0" class="black" align="left" background="images/gt_mid1.gif" valign="middle" width="100%"><table width="100%" border="0"><tr><td width="10"></td><td width="100%" class="black">'+
                                                'The Average Score for a 1UP game is an aggregate of the review scores from 1UP and its users. It represents a combination of the opinions of 1UP\'s professional game reviewers and community users. Games with average scores in the 9-10 range should generally be considered excellent, 7-8.5 good, 5-6.5 average, 3-4.5 bad, and 0-2.5 terrible.' +
                                                '</td><td width="10"></td></tr></table></tr><tr><td border="0" class="black" align="left" background="images/gt_mid1.gif" valign="middle" width="100%"><table width="100%" border="0"><tr><td width="100%" class="black"><img src="images/tran.gif" height="1"></td></tr></table></tr><tr><td border="0" align="center" background="images/gt_bottom1.gif" height="10" valign="middle" width="325"></td></tr></tbody></table>';
                }
             },
             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("Tooltip1.toggleVis('"+this.tipID+"', 'visible');Tooltip1.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;
               } 
               if (msg.substring(0,msg.indexOf('_')) == "tradein"){
                   this.list_bool[msg.substring(0,msg.indexOf('_'))] = true;
                   this.list_html[msg.substring(0,msg.indexOf('_'))] = 
                        '<table border="0" cellpadding="0" cellspacing="0" width="325">'+
                        '<tbody><tr><td border="0" class="black" align="center" background="images/tooltip/gt_top1.gif" height="26" valign="middle" width="325"><b>Trade-In Values</b></td></tr>'+
                        '<tr><td border="0" class="black" align="left" background="images/tooltip/gt_mid1.gif" valign="middle" width="100%">'+
                        '<table width="100%" border="0"><tr><td width="100%" class="black"><img src="images/tran.gif" height="1"></td></tr></table></tr><tr><td border="0" class="black" align="left" background="images/tooltip/gt_mid1.gif" valign="middle" width="100%"><table width="100%" border="0"><tr><td width="10"></td><td width="100%" class="black">'+
                        '<tr><td width="10"></td>'+ 
                        '<td width="220"><b>Complete Game</b><br>(Original Case + Manual + Artwork)</td><td width="85">$'+Tooltip1.c4+'</td>'+
                        '</td><td width="10"></td></tr>' +
                        '<tr><td width="10"></td>'+ 
                        '<td width="220"><b>Incomplete Game</b><br>(Game Only, Game + Manual or Game + Artwork)</td><td width="85">$'+Tooltip1.c1+'</td>'+
                        '</td><td width="10"></td></tr>' +
                        /*
                        '<tr><td width="10"></td>'+ 
                        '<td width="200">'+'Game + Artwork (GA)'+'</td><td width="125">$'+Tooltip1.c2+'</td>'+
                        '</td><td width="10"></td></tr>' +
                        '<tr><td width="10"></td>'+ 
                        '<td width="200">'+'Game + Manual (GM)'+'</td><td width="125">$'+Tooltip1.c3+'</td>'+
                        '</td><td width="10"></td></tr>' +
                        
                        '<tr><td width="10"></td>'+ 
                        '<td width="200">'+'Game + Case (GC)'+'</td><td width="125">$'+Tooltip1.c4+'</td>'+
                        */
                        '</td><td width="10"></td></tr>' +
                        '</table></tr><tr><td border="0" class="black" align="left" background="images/tooltip/gt_mid1.gif" valign="middle" width="100%"><table width="100%" border="0"><tr><td width="100%" class="black"><img src="images/tran.gif" height="1"></td></tr></table></tr><tr><td border="0" align="center" background="images/tooltip/gt_bottom1.gif" height="10" valign="middle" width="325"></td></tr></tbody></table>';   
               }
               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;
               } else {
                  xajax_get_game_status(msg);
                  return false;
               }
             },
             ajaxResponse:function(msg){
                    if (this.tip && this.last_sender && this.last_sender.id == msg) {
                      this.list_bool[msg.substring(0,msg.indexOf('_'))] = true;
                      this.list_html[msg.substring(0,msg.indexOf('_'))] = this.tip.innerHTML;
                      this.positionTip(null, msg);
                      this.timer=setTimeout("Tooltip1.toggleVis('"+this.tipID+"', 'visible');Tooltip1.toggleVis('"+this.arrID+"', 'visible')",this.showDelay);
                    }
             }
             ,positionTip:function(e, msg){
                if(this.tip&&this.tip.style){
                  
                   position_scr.init(msg, this.tipID);
                   position_scr.compareA(this.x, this.y);

                   if (msg.substring(0,msg.indexOf('_')) == "tradein") {
                     this.arr.innerHTML = "<img src='images/tooltip/" + position_scr.image_name + "'>";
                   } else {
                     this.arr.innerHTML = "<img src='images/" + position_scr.image_name + "'>";
                   }
                   this.arr.style.left = position_scr.arrX+"px";
                   this.arr.style.top =  position_scr.arrY+"px";
                   this.tip.style.left = position_scr.tipX +"px";
                   this.tip.style.top =  position_scr.tipY +"px";
                }
             }
             ,hide:function(){
                if(this.timer){
                   clearTimeout(this.timer);
                   this.timer=0;
                }
                this.timer=setTimeout("Tooltip1.toggleVis('"+this.tipID+"', 'hidden'); Tooltip1.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);
                Tooltip1.positionTip(e);
             }
};

function doTooltip1(e, msg, c1, c2, c3, c4) {

  if ( typeof Tooltip1 == "undefined" || !Tooltip1.ready ) return;
  Tooltip1.clearTimer();
  var tip = document.getElementById? document.getElementById(Tooltip1.tipID): null;
  if ( tip && tip.onmouseout == null ) {
      tip.onmouseout = Tooltip1.tipOutCheck;
      tip.onmouseover = Tooltip1.clearTimer;
  }
  var arr = document.getElementById? document.getElementById(Tooltip1.arrID): null;
  if ( arr && arr.onmouseout == null ) {
      arr.onmouseout = Tooltip1.tipOutCheck;
      arr.onmouseover = Tooltip1.clearTimer;
  }
  Tooltip1.c1 = c1;
  Tooltip1.c2 = c2;
  Tooltip1.c3 = c3;
  Tooltip1.c4 = c4;
  Tooltip1.show(e, msg);
}

function hideTip1() {
  if ( typeof Tooltip1 == "undefined" || !Tooltip1.ready ) return;
  Tooltip1.hide();
  Tooltip1.timerId = setTimeout("Tooltip1.hide()", 300);
}

Tooltip1.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) && Tooltip1.sender != toEl) {
    Tooltip1.hide(); 
  } else {
//       dw_event.remove(Tooltip1.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;
}

Tooltip1.timerId = 0;
Tooltip1.clearTimer = function() {
  if (Tooltip1.timerId) { clearTimeout(Tooltip1.timerId); Tooltip1.timerId = 0; }
}

Tooltip1.unHookHover = function () {
    var tip = document.getElementById? document.getElementById(Tooltip1.tipID): null;
    if (tip) {
        tip.onmouseover = null; 
        tip.onmouseout = null;
        tip = null;
    }
}
dw_event.add(window, "unload", Tooltip1.unHookHover, true);
