var Tooltip = {
    volgMuis: false,
    offsetX: 4,			// horizontale verplaatsing tooltip t.o.v. muispositie
    offsetY: 4,			// verticale verplaatsing tooltip t.o.v. muispositie
    tipID: "tipDiv",
    showDelay: 100,
    hideDelay: 200,
    
    klaar:false, timer:null, tip:null, 
  
    init: function() {  
        if ( document.createElement && document.body && typeof document.body.appendChild != "undefined" ) {
            if ( !document.getElementById(this.tipID) ) {
                var el = document.createElement("DIV");
                el.id = this.tipID; document.body.appendChild(el);}
            this.klaar = true;}},
    Toon: function(e, inhoud) {
        if (this.timer) { clearTimeout(this.timer);	this.timer = 0; }
        this.tip = document.getElementById( this.tipID );
        if (this.volgMuis)
            eventdetectie.toevoegen( document, "mousemove", this.traceerMuis, true );
        this.SchrijfTip("");  // voor mac ie
        this.SchrijfTip(inhoud);
        schermdetectie.haalAlles();
        this.PlaatsTip(e);
        this.timer = setTimeout("Tooltip.WisselZichtbaar('" + this.tipID + "', 'visible')", this.showDelay);},
    SchrijfTip: function(inhoud) {
        if ( this.tip && typeof this.tip.innerHTML != "undefined" ) this.tip.innerHTML = inhoud;},
    PlaatsTip: function(e) {
        if ( this.tip && this.tip.style ) {
            // put e.pageX/Y first! (for Safari)
            var x = e.pageX? e.pageX: e.clientX + schermdetectie.scrollX;
            var y = e.pageY? e.pageY: e.clientY + schermdetectie.scrollY; 
            if ( x + this.tip.offsetWidth + this.offsetX > schermdetectie.width + schermdetectie.scrollX ) {
                x = x - this.tip.offsetWidth - this.offsetX;
                if ( x < 0 ) x = 0;
            } else x = x + this.offsetX;
            if ( y + this.tip.offsetHeight + this.offsetY > schermdetectie.height + schermdetectie.scrollY ) {
                y = y - this.tip.offsetHeight - this.offsetY;
                if ( y < schermdetectie.scrollY ) y = schermdetectie.height + schermdetectie.scrollY - this.tip.offsetHeight;
            } else y = y + this.offsetY;
            this.tip.style.left = x + "px"; this.tip.style.top = y + "px";}},
    Verberg: function() {
        if (this.timer) { clearTimeout(this.timer);	this.timer = 0; }
        this.timer = setTimeout("Tooltip.WisselZichtbaar('" + this.tipID + "', 'hidden')", this.hideDelay);
        if (this.volgMuis) // release mousemove
            eventdetectie.verwijderen( document, "mousemove", this.traceerMuis, true );
        this.tip = null; },
    WisselZichtbaar: function(id, vis) { 
        var el = document.getElementById(id);
        if (el) el.style.visibility = vis;},
    traceerMuis: function(e) {
    	e = eventdetectie.maakDOM(e);
     	Tooltip.PlaatsTip(e);}}
  
var eventdetectie = {
  toevoegen: function(obj, etype, fp, cap) {
    cap = cap || false;
    if (obj.addEventListener) obj.addEventListener(etype, fp, cap);
    else if (obj.attachEvent) obj.attachEvent("on" + etype, fp);}, 
  verwijderen: function(obj, etype, fp, cap) {
    cap = cap || false;
    if (obj.removeEventListener) obj.removeEventListener(etype, fp, cap);
    else if (obj.detachEvent) obj.detachEvent("on" + etype, fp);}, 
  maakDOM: function(e) { 
    e = e? e: window.event;
    e.tgt = e.srcElement? e.srcElement: e.target;
    if (!e.preventDefault) e.preventDefault = function () { return false; }
    if (!e.stopPropagation) e.stopPropagation = function () { if (window.event) window.event.cancelBubble = true; }
    return e;}}

var schermdetectie = {
  haalSchermBreedte: function () {
    this.width = 0;
    if (window.innerWidth) this.width = window.innerWidth - 18;
    else if (document.documentElement && document.documentElement.clientWidth) 
  		this.width = document.documentElement.clientWidth;
    else if (document.body && document.body.clientWidth) 
  		this.width = document.body.clientWidth;},
  haalSchermHoogte: function () {
    this.height = 0;
    if (window.innerHeight) this.height = window.innerHeight - 18;
  	else if (document.documentElement && document.documentElement.clientHeight) 
  		this.height = document.documentElement.clientHeight;
  	else if (document.body && document.body.clientHeight) 
  		this.height = document.body.clientHeight;},
  haalMuisX: function () {
    this.scrollX = 0;
  	if (typeof window.pageXOffset == "number") this.scrollX = window.pageXOffset;
  	else if (document.documentElement && document.documentElement.scrollLeft)
  		this.scrollX = document.documentElement.scrollLeft;
  	else if (document.body && document.body.scrollLeft) 
  		this.scrollX = document.body.scrollLeft; 
  	else if (window.scrollX) this.scrollX = window.scrollX;},
  haalMuisY: function () {
    this.scrollY = 0;    
    if (typeof window.pageYOffset == "number") this.scrollY = window.pageYOffset;
    else if (document.documentElement && document.documentElement.scrollTop)
  		this.scrollY = document.documentElement.scrollTop;
  	else if (document.body && document.body.scrollTop) 
  		this.scrollY = document.body.scrollTop; 
  	else if (window.scrollY) this.scrollY = window.scrollY;},
  haalAlles: function () {
    this.haalSchermBreedte(); this.haalSchermHoogte();
    this.haalMuisX(); this.haalMuisY();}}

function maakTooltip(e, inhoud) {
  if ( typeof Tooltip == "undefined" || !Tooltip.klaar ) return;
  Tooltip.clearTimer();
  var tip = document.getElementById? document.getElementById(Tooltip.tipID): null;
  if ( tip && tip.onmouseout == null ) {
      tip.onmouseout = Tooltip.checkMuisUit;
      tip.onmouseover = Tooltip.clearTimer;}
  Tooltip.Toon(e, inhoud);}

function verbergTip() {
  if ( typeof Tooltip == "undefined" || !Tooltip.klaar ) return;
  Tooltip.timerId = setTimeout("Tooltip.Verberg()", 300);}

Tooltip.checkMuisUit = function(e) {
  e = eventdetectie.maakDOM(e);
  var toEl = e.relatedTarget? e.relatedTarget: e.toElement;
  if ( this != toEl && !container(toEl, this) ) Tooltip.Verberg();}

function container(oNode, oCont) {
  if (!oNode) return; 
  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.hooverUit = function () {
    var tip = document.getElementById? document.getElementById(Tooltip.tipID): null;
    if (tip) {
        tip.onmouseover = null; 
        tip.onmouseout = null;
        tip = null;}}

eventdetectie.toevoegen(window, "unload", Tooltip.hooverUit, true);
