var Infobulle = function() {};

Infobulle.container	= new Element('div',	{	'class'	:	'infobulleContainer'	});
Infobulle.title		= new Element('div',	{	'class'	:	'infobulleTitle'		});
Infobulle.content	= new Element('div',	{	'class'	:	'infobulleContent'		});

Infobulle.X = 0;
Infobulle.Y = 0;
Infobulle.data = new Array();
Infobulle.cursor1 = false;
Infobulle.cursor2 = false;

Infobulle.init = function(object) {
	document.onmousemove = Infobulle.getPosition;
	document.getElements('.'+object).each(function(item) {
		item.onmouseover = function() {
			var title = Infobulle.data[item.uid].title;
			var text = Infobulle.data[item.uid].text;
			Infobulle.show(title, text);
			Infobulle.cursor2 = true;
		};
		item.onmouseout = function() {
			Infobulle.hide();
			Infobulle.cursor2 = false;
		};
	});
	Infobulle.container.onmouseover = function() {	Infobulle.cursor1 = true;	};
	Infobulle.container.onmouseout = function() {
		Infobulle.hide();
		Infobulle.cursor1 = false;
	};
	
};

Infobulle.add = function(item, title, text) {
	Infobulle.data[item.uid] = new Object();
	Infobulle.data[item.uid].title = title;
	Infobulle.data[item.uid].text = text;
};

Infobulle.show = function(title, text) {
	Infobulle.container.inject(document.getElements('body')[0], 'top');
	Infobulle.content.inject(Infobulle.container, 'top');
	Infobulle.title.inject(Infobulle.container, 'top');
	Infobulle.title.innerHTML = title;
	Infobulle.content.innerHTML = text;
	Infobulle.container.style.left = (Infobulle.X-20)+'px';
	Infobulle.container.style.top = (Infobulle.Y+5)+'px';
	Infobulle.cursor = false;
};

Infobulle.hide = function() {
	window.setTimeout(function() {
		if(!Infobulle.cursor1 && !Infobulle.cursor2)
			Infobulle.container.destroy();
	}, 100);
};

Infobulle.getPosition = function(e){
	var DocRef;
	if(e){
		Infobulle.X = e.pageX;
		Infobulle.Y = e.pageY;
	}
	else{
		Infobulle.X = event.clientX;
		Infobulle.Y = event.clientY;

		if( document.documentElement && document.documentElement.clientWidth)
			DocRef = document.documentElement;
		else
			DocRef = document.body;

		Infobulle.X += DocRef.scrollLeft;
		Infobulle.Y += DocRef.scrollTop;
	}
};
