var BFRoundedTooltip=function(){
	var id = 'bfrtt';
	var top = 3;
	var left = 3;
	var maxw = 300;
	var speed = 10;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt,tth,tt_t,t,c,b,h,tt_cont;
	var ie = document.all ? true : false;
	return{
		show:function(v,w){
			if(tt == null){

                // Brand new
                tth = document.createElement('div');
                tth.setAttribute('id',id);

                tt = document.createElement('div');
                tt.style.display='block';
                tt.style.margin='0px auto;';
                tt.className = "rounded-grey-border";

                tt_t = document.createElement('div');
                tt_t.className="t";

                tt_b = document.createElement('div');
                tt_b.className="b";

                tt_l = document.createElement('div');
                tt_l.className="l";

                tt_r = document.createElement('div');
                tt_r.className="r";

                tt_bl = document.createElement('div');
                tt_bl.className="bl";

                tt_br = document.createElement('div');
                tt_br.className="br";

                tt_tl = document.createElement('div');
                tt_tl.className="tl";

                tt_tr = document.createElement('div');
                tt_tr.className="tr";

                tt_cont = document.createElement('div');
                tt_cont.className="grey2-create-content";
                tt_cont.style.padding="5px";

                tt_tr.appendChild(tt_cont);
                tt_tl.appendChild(tt_tr);
                tt_br.appendChild(tt_tl);
                tt_bl.appendChild(tt_br);
                tt_r.appendChild(tt_bl);
                tt_l.appendChild(tt_r);
                tt_b.appendChild(tt_l);
                tt_t.appendChild(tt_b);
                tt.appendChild(tt_t);

                tth.appendChild(tt);

                /*
                // OLD
                tth = document.createElement('div');
                tth.setAttribute('id',id);
                tt = document.createElement('div');
                tt.style.display='block';
                tt.setAttribute('id','roundedcornr_box_617176');
                // top
                t = document.createElement('div');
                //t.setAttribute('id', id + 'top');
                t.setAttribute('id', 'roundedcornr_top_617176');
                td = document.createElement('div');
                t.appendChild(td);
                // content
                c = document.createElement('div');
                //c.setAttribute('id', id + 'cont');
                c.setAttribute('id', 'roundedcornr_content_617176');
                // bottom
                b = document.createElement('div');
				//b.setAttribute('id',id + 'bot');
                b.setAttribute('id', 'roundedcornr_bottom_617176');
                bd = document.createElement('div');
                b.appendChild(bd);

                tt.appendChild(t);
                tt.appendChild(c);
                tt.appendChild(b);

                tth.appendChild(tt);
                */

                document.body.appendChild(tth);
                tth.style.opacity = 0;
                tth.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;

                /*
				tt = document.createElement('div');
				tt.setAttribute('id',id);
				t = document.createElement('div');
				t.setAttribute('id',id + 'top');
				c = document.createElement('div');
				c.setAttribute('id',id + 'cont');
				b = document.createElement('div');
				b.setAttribute('id',id + 'bot');
				tt.appendChild(t);
				tt.appendChild(c);
				tt.appendChild(b);
				document.body.appendChild(tt);
				tt.style.opacity = 0;
				tt.style.filter = 'alpha(opacity=0)';
				document.onmousemove = this.pos;
                */
			}
			tth.style.display = 'block';
			//c.innerHTML = v;
            tt_cont.innerHTML = v;
			if(w==undefined) { w = "auto"; }
            
            tth.style.width = 'auto';
            tt.style.width = 'auto';
            tt_t.style.width = 'auto';

			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tth.style.width = tth.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tth.offsetWidth > maxw){tth.style.width = maxw + 'px'}
			h = parseInt(tth.offsetHeight) + top;
			clearInterval(tth.timer);
			tth.timer = setInterval(function(){BFRoundedTooltip.fade(1)},timer);
		},
		pos:function(e){
			var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
			var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
			tth.style.top = (u - h) + 'px';
			tth.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);
				tth.style.opacity = alpha * .01;
				tth.style.filter = 'alpha(opacity=' + alpha + ')';
			}else{
				clearInterval(tth.timer);
				if(d == -1){tth.style.display = 'none'}
			}
		},
		hide:function(){
            clearInterval(tth.timer);
			tth.timer = setInterval(function(){BFRoundedTooltip.fade(-1)},timer);
		}
	};
}();