// Developed by Beat
var tooltip = {
    max_width: 0,
    zIndex: 99,
    amove: false,
    padding: {x: 10, y: 20},
    state: true, // Inlying parameter, always must be TRUE
    timer: null,
    emove: false,
    // Begin function declaration
    XYpos: function(e){
       if (tooltip.state){
            oCanvas =  document.getElementsByTagName((document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY")[0];
			x = window.event ? event.clientX + oCanvas.scrollLeft : e.pageX;
			y = window.event ? event.clientY + oCanvas.scrollTop : e.pageY;
            if (tooltip.emove) tooltip.setDiv(x, y);
       }
	},
    makeDiv: function () {
       var objBody = document.getElementsByTagName("body").item(0);

       var objMain = document.createElement("DIV");
       objMain.setAttribute('id','tip_main');
       objMain.style.zIndex = tooltip.zIndex++;
       objMain.className = "tooltip_main";

       var objArr = document.createElement("DIV");
       objArr.className = "tooltip_arr";
       objMain.appendChild(objArr);

       var objText = document.createElement("DIV");
       objText.className = "tooltip_text";
       objText.setAttribute('id','tip_text');
       objMain.appendChild(objText);

       document.body.appendChild(objMain);
    },
    setDiv: function (x,y) {

        if (!$("tip_main")) return;
        try {
          oCanvas =  document.getElementsByTagName((document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY")[0];
          w_width = oCanvas.clientWidth ? oCanvas.clientWidth + oCanvas.scrollLeft : window.innerWidth + window.pageXOffset;
		  w_height = window.innerHeight ? window.innerHeight + window.pageYOffset : oCanvas.clientHeight + oCanvas.scrollTop;
        }
        catch (e) {}
		t_width = $("tip_main").offsetWidth;
		t_height = $("tip_main").offsetHeight;
		$("tip_main").style.left = x + tooltip.padding.x + "px";
		$("tip_main").style.top = y + tooltip.padding.y + "px";
		if (x + t_width > w_width) $("tip_main").style.left = w_width - t_width + "px";
		if (y + t_height > w_height) $("tip_main").style.top = w_height - t_height + "px";
    },
    show: function (cont,c) {
       if (!c) this.emove = true;
       if (tooltip.amove) tooltip.state = true;
       $("tip_text").innerHTML = cont;
       if (typeof x != 'undefined' && typeof y != 'undefined') tooltip.setDiv(x,y);
       $("tip_main").style.display = 'block';
    },
    showDelay: function (cont,t) {
      this.timer = setTimeout(function () {
        tooltip.show(cont,false);
      },(typeof t == 'number') ? t : 500);
    },
    hide: function () {
      this.emove = false;
      if (tooltip.amove) tooltip.state = false;
      $("tip_main").style.display = 'none';
      if (this.timer) {
        clearTimeout(this.timer);
        this.timer = null;
      }
    }
}
addEvent(document,'mousemove',tooltip.XYpos);