/*************************************************************************
  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 Tooltip1 = {
             offX : 1,
             offY : 148,
             tipID: "tipDiv1",
             ready:false,
             tip: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.zIndex = 1;
                      document.body.appendChild(el1);
                   }
                   this.ready=true;
                   this.list_bool = new Array();
                   this.list_html = new Array();

                }
             },
             show:function(e,msg){
                if (!this.ttready)  return;
                var sender = document.getElementById(msg);
                if (sender == this.sender) return;

                this.tip=document.getElementById(this.tipID);
                this.sender=sender;
                this.sender_id = this.sender.id.substring(0,this.sender.id.indexOf('_'));
                this.last_sender=sender;
                this.writeTip(e, msg);
                this.positionTip(e, msg);
             }
             ,writeTip:function(e,msg){

               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){
                   this.offY = 148 + (document.getElementById('main_table1') ? document.getElementById('main_table1').style.height.replace("px", "")*1:0);
                 
                tt =  (document.getElementById('main_table').width*1 - document.getElementById('sub_table').width*1);
                document.getElementById('wish_div').width = tt?tt:1;

                   position1.init(msg, this.tipID);
                   position1.compare();

                   if(!(viewport.scrollY && viewport.scrollY > this.offY))
                      this.tip.style.top =  this.offY + "px";
                   else
                      if(((viewport.scrollY && viewport.scrollY > this.offY)  &&  (( viewport.scrollY + position1.TipH) < position1.SenderH)))
                         this.tip.style.top =  position1.tipY + "px";
                      else
                         if(((viewport.scrollY && viewport.scrollY > this.offY)  &&  (( viewport.scrollY + position1.TipH) > position1.SenderH)))
                             this.tip.style.top =  position1.SenderH - position1.TipH + "px";

                   left_ = position1.tipX - document.getElementById('wish_div').width;

                   if(document.getElementById('wish_content_left') && left_ > document.getElementById('wish_content_left').width*1)
                      left_ = (left_ - document.getElementById('wish_content_left').width*1)-1;

                   this.tip.style.left = left_ + "px";


                }
             }
             ,hide:function(){

                Tooltip1.toggleVis('"+this.tipID+"', 'hidden')
                this.tip=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) {

  if ( typeof Tooltip1 == "undefined" || !Tooltip1.ready ) return;

  Tooltip1.show(e, msg);
}

function hideTip1() {
  if ( typeof Tooltip1 == "undefined" || !Tooltip1.ready ) return;

  Tooltip1.hide();
}

var position1 = {
  init : function (sender, tipID) {
     this.sender = sender;
     this.tipID = tipID;
     viewport.getAll();
     this.getSenderTop();
     this.getSenderLeft();
     this.getSenderHeight();
     this.getSenderWidth();
     this.getTipHeight();
     this.getTipWidth();
     this.tipW = 0;
  },

  compare : function () {

     this.is_hidden_top = (viewport.scrollY>this.SenderY);
     this.is_hidden_bottom = ((this.SenderY+this.SenderH) > (viewport.scrollY+viewport.height));
     if (this.is_hidden_top && this.is_hidden_bottom) this.is_hidden_bottom = false;
     
     if (this.is_hidden_top || this.is_hidden_bottom) {
        if (this.is_hidden_top) {
           this.image_name = "up";
           this.tipY = viewport.scrollY + 5;
        }
        if (this.is_hidden_bottom) {
           this.image_name = "lower";
           this.tipY = viewport.scrollY + viewport.height - this.TipH;
        }
     }     

     this.tipX = this.SenderX*1 + this.SenderW*1;

  },


  getSenderTop : function (){
     yPos = document.getElementById(this.sender).offsetTop;
     tempEl = document.getElementById(this.sender).offsetParent;
       while (tempEl != null) {
        yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
     }
     this.SenderY = yPos;
  },

  getSenderLeft : function (){
     xPos = document.getElementById(this.sender).offsetLeft;
     tempEl = document.getElementById(this.sender).offsetParent;

       while (tempEl != null) {
        xPos += tempEl.offsetLeft;
        tempEl = tempEl.offsetParent;
      }
     this.SenderX = xPos;

  },

  getSenderHeight : function (){
    if (document.getElementById(this.sender).height) {
     this.SenderH = document.getElementById(this.sender).height; 
    } else {
      if (document.getElementById(this.sender).offsetHeight) {
       this.SenderH = document.getElementById(this.sender).offsetHeight; 
      } 
    }
  },

  getSenderWidth : function (){
    if (document.getElementById(this.sender).width) {
     this.SenderW = document.getElementById(this.sender).width;
    } else {
      if (document.getElementById(this.sender).offsetWidth) {
       this.SenderW = document.getElementById(this.sender).offsetWidth; 
      } 
    }
  },
  getTipHeight : function (){
     this.TipH = document.getElementById(this.tipID).offsetHeight; 
  },
  getTipWidth : function (){
     this.TipW = document.getElementById(this.tipID).offsetWidth;
  }

}

function getClientWidth() {
  return document.compatMode=='CSS1Compat' && !window.opera?document.documentElement.clientWidth:document.body.clientWidth;
}

function show_width() {
 var width = getClientWidth();

 var opera = (navigator.userAgent.indexOf('Opera') >= 0)? true : false;
 var ie = (document.all && !opera)? true : false;
 var dom = (document.getElementById && !ie && !opera)? true : false; 


 if (width <= 1024) {
  document.getElementById("main_table").width = "993";
 } else {
  document.getElementById("main_table").width = "800";
 }

}
function loadTooltip1(e){

  Tooltip1.init(); 
  doTooltip1(e, 'wish_div');
  div_resize();
 
}
function div_resize(){
   
  limit =  Math.round((document.getElementById('main_table').offsetHeight-270) / 55);
  if(document.getElementById('queue_count') &&  document.getElementById('queue_count').value > limit){
     document.getElementById('wish_div_crop').style.height =  limit * 55 + "px";
  }

}