dojo.addOnLoad(function(){
	tooltips = dojo.query('.tooltip');
	dojo.forEach(tooltips,function(tt){
		ids = tt.id.split('_');
		over = dojo.byId(ids[0]);
		dojo.connect(over,'onmouseover',function(e) { 
			var t = new ToolTip(ids[0]);
			tt = dojo.byId(e.target.id + '_tt');
			t.show(tt.innerHTML);
		});
		dojo.connect(over,'onmouseout',function(e) { 
			var t = new ToolTip(ids[0]);
			tt = dojo.byId(e.target.id + '_tt');
			t.hide();
		});
	});
});



ToolTip=function(id){
	var id = id + '-tt';
	var top = 3;
	var left = 3;
	var maxw = 450;
	var speed = 10;
	var timer = 20;
	var endalpha = 95;
	var alpha = 0;
	var tt;
    var t;
    var c;
    var b;
    var h;
	var ie = document.all ? true : false;
	if(!dojo.byId(id)){
			tt = document.createElement('div');
			tt.setAttribute('id',id);
			tt.setAttribute('class','tooltip-bubble');
			tt.setAttribute('className','tooltip-bubble');
			t = document.createElement('div');
			t.setAttribute('id',id + 'top');
			t.setAttribute('class','tooltip-bubble-top');
			t.setAttribute('className','tooltip-bubble-top');
			c = document.createElement('div');
			c.setAttribute('id',id + 'cont');
			c.setAttribute('class','tooltip-bubble-cont');
			c.setAttribute('className','tooltip-bubble-cont');
			b = document.createElement('div');
			b.setAttribute('id',id + 'bot');
			b.setAttribute('class','tooltip-bubble-bottom');
			b.setAttribute('className','tooltip-bubble-bottom');
			tt.appendChild(t);
			tt.appendChild(c);
			tt.appendChild(b);
			document.body.appendChild(tt);
			tt = dojo.byId(id);
	}else{
		tt = dojo.byId(id);
		c = dojo.byId(id + 'cont');
		t = dojo.byId(id + 'top');
		b = dojo.byId(id + 'bot');
	};
	this.show = function(v,w){
			tt.style.opacity = 0;
			tt.style.filter = 'alpha(opacity=0)';
			document.onmousemove = this.pos;
			tt.style.display = 'block';
			c.innerHTML = v;
			tt.style.width = w ? w + 'px' : 'auto';
			if(!w && ie){
				t.style.display = 'none';
				b.style.display = 'none';
				tt.style.width = tt.offsetWidth;
				t.style.display = 'block';
				b.style.display = 'block';
			}
			if(tt.offsetWidth > maxw){tt.style.width = maxw + 'px'}
			h = parseInt(tt.offsetHeight) + top;
			clearInterval(tt.timer);
			var self = this;
			tt.timer = setInterval(function(){self.fade(1);},timer);
		},
	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';
		},
	this.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'}
			}
		},
	this.hide = function(){
			clearInterval(tt.timer);
			var self = this;
			tt.timer = setInterval(function(){self.fade(-1);},timer);
		}
};
