﻿
var tooltip = function() {
    var id = 'tt';
    var top = 5;
    var left = -23;
    var maxw = 300;
    var speed = 10;
    var timer = 20;
    var endalpha = 100;
    var alpha = 0;
    var tt, t, c, b, h, r, clear;
    var ie = document.all ? true : false;
    var ie6 = (navigator.userAgent.indexOf('MSIE 6') > -1);

    return {
        show: function(v, y, w)
        {

            if (ie6)
                this._hideDropDowns(true);

            if (tt == null) {
                tt = document.createElement('div');
                tt.className = 'tooltip_container';

                c = document.createElement('div');
                b = document.createElement('div');

                tt.appendChild(c);
                tt.appendChild(b);

                document.body.appendChild(tt);

                tt.style.opacity = 0;
                tt.style.filter = 'alpha(opacity=0)';

                if(arguments.length < 4)
                    document.onmousemove = this.pos;
            }

            c.className = 'tooltip_' + y + '_content';
            b.className = 'tooltip_' + y + '_bottom';


            tt.style.display = 'block';
            c.innerHTML = v;
            tt.style.width = w ? w + 'px' : 'auto';

            if (!w && ie) {
                b.style.display = 'none';
                tt.style.width = tt.offsetWidth;
                b.style.display = 'block';
            }

            if (tt.offsetWidth > maxw) {
                tt.style.width = maxw + 'px';
            }

            h = parseInt(tt.offsetHeight) + top;
            clearInterval(tt.timer);
            tt.timer = setInterval(function() { tooltip.fade(1) }, timer);
            
            return this;
        },

        pos: function(e)
        {
            var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
            var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
            tt.style.top = (u - h) + 'px';
            tt.style.left = (l + left) + 'px';
        },
        
        position: function(e)
        {
            var u = ie ? e.clientY + document.documentElement.scrollTop : e.pageY;
            var l = ie ? e.clientX + document.documentElement.scrollLeft : e.pageX;
            tt.style.top = (u - h) + 'px';
            tt.style.left = (l + left) + 'px';
        },

        fade: function(d)
        {
            var a = alpha;

            if ((a != endalpha && d == 1) || (a != 0 && d == -1)) {
                var i = speed;
                if (endalpha - a < speed && d == 1)
                    i = endalpha - a;
                else if (alpha < speed && d == -1)
                    i = a;

                alpha = a + (i * d);
                tt.style.opacity = alpha * .01;
                tt.style.filter = 'alpha(opacity=' + alpha + ')';

            }
            else {
                clearInterval(tt.timer);
                if (d == -1) { tt.style.display = 'none' }
            }
        },

        hide: function(method)
        {
			if(method == 'fast')
			{
				tt.style.opacity = 1;
                tt.style.filter = 'alpha(opacity=100)';
                tt.style.display = 'none';
			}
			else
			{
				clearInterval(tt.timer);
				tt.timer = setInterval(function() {tooltip.fade(-1)}, timer);
				if (ie6)
					this._hideDropDowns(false);
			}
        },

        _hideDropDowns: function(flag) {
            var dropdowns = document.getElementsByTagName('select');
            for (var i = 0; i < dropdowns.length; i++)
                dropdowns[i].style.visibility = (flag ? 'hidden' : 'visible');
        }

    };
} ();