// Copyright � 2002-2005 Picsel Media Design
// This script is the intelectual property of Alexandru Buga a.k.a. Picselutz
// You cand use it anyway you want as long as you leave this copyright intact
// and you send me an e-mail.
//
// Soft modified by Jakub Spanihel a.k.a. Kvezt (kvezt.wz.cz)
//
// THIS SCRIPT IS NOT FOR COMMERCIAL USE.

var cw=0, ch=0;

tooltip = {
        name : "js-tooltipDiv",	// div pop-up ID
        offsetX : -70,
        offsetY : 15,
        tip : null
};

tooltip.init = function () {
   if (!document.getElementById) return;
   
		var body = document.getElementsByTagName ('body').item(0);
		var div = document.createElement('div');
		div.id = this.name;
		body.appendChild(div);
        
        this.tip = document.getElementById (this.name);
        if (this.tip) document.onmousemove = function (evt) {tooltip.move (evt)};

		/*- <a title> -*/
        var anchors = document.getElementsByTagName ("a");
        for (var i = 0; i < anchors.length; i ++) {
                a = anchors[i];
                tit = a.getAttribute('title');
                if (tit) {
               for (var c = 0; c < 5; c ++) {
                  tit = tit.replace('\\','<br />');
               }
					a.setAttribute('nicetitle',tit);
					a.removeAttribute('title');
					a.onmouseover = function () {tooltip.show (this.getAttribute('nicetitle'))};
					a.onmouseout = function () {tooltip.hide ()};
                }
        }
		/*- <span class="help"> -*/
        var spans = document.getElementsByTagName ("span");
        for (var i = 0; i < spans.length; i ++) {
                s = spans[i];
                tit = s.getAttribute('title');
                if (tit) {
               for (var d = 0; d < 5; d ++) {
                  tit = tit.replace('\\','<br />');
               }
					s.setAttribute('nicetitle',tit);
					s.removeAttribute('title');
					s.onmouseover = function () {tooltip.show (this.getAttribute('nicetitle'))};
					s.onmouseout = function () {tooltip.hide ()};
                }
        }
      //document.onmouseover = function () {tooltip.show ('asdfas')};
};
tooltip.move = function (evt) {
        var x=0, y=0, maxleft=0, maxtop=0;
        
        if (document.all) {
                x = (document.documentElement && document.documentElement.scrollLeft) ? document.documentElement.scrollLeft : document.body.scrollLeft;
                y = (document.documentElement && document.documentElement.scrollTop) ? document.documentElement.scrollTop : document.body.scrollTop;
                x += window.event.clientX;
                y += window.event.clientY;
                cw = document.body.scrollWidth;
                ch = document.documentElement.clientHeight
        } else {
                x = evt.pageX;
                y = evt.pageY;
                cw = document.body.scrollWidth;
                ch = window.innerHeight;
        }
        maxleft = cw - (this.tip.offsetWidth + this.offsetX);
        minleft = (this.tip.offsetWidth + this.offsetX);
        maxtop = ch - (this.tip.offsetHeight + this.offsetY);
        

         if(x>=maxleft) {
            posleft = maxleft + this.offsetX;
         } else if(x<=minleft) {
            posleft = minleft + this.offsetX;
         } else {
            posleft = x + this.offsetX;
         }
         if(y>=maxtop) {
            //postop = y - (this.offsetY + this.tip.offsetHeight);
            postop = y + this.offsetY;
         } else {
            postop = y + this.offsetY;
         }
         this.tip.style.left = posleft + "px";
         this.tip.style.top = postop + "px";
         /*     
         this.tip.innerHTML = ""+
                     "maxleft: " + maxleft + "<br>" +
                     "minleft: " + minleft + "<br>" +
                     "mouse x: " + x + "<br>" +
                     "maxtop: " + maxtop + "<br>" +
                     "mouse y: " + y + "<br>" +
                     "posleft: " + posleft + "<br>" +
                     "postop: " + postop + "<br>" +
                     "";
         /**/
};


tooltip.show = function (text) {
        if (!this.tip) return;
        this.tip.innerHTML = text;
        this.tip.style.visibility = "visible";
        this.tip.style.display = "block";
};
tooltip.hide = function () {
        if (!this.tip) return;
        this.tip.style.visibility = "hidden";
        this.tip.style.display = "none";
        this.tip.innerHTML = "";
};

