var Bubbles = function() {
	this.hash = {};
}

Bubbles.prototype.findPos = function(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

Bubbles.prototype.isEmpty = function() {
	var count = 0;
	for (var name in this.hash) {
		count++;
	}
	if (count > 0)
		return false;
	return true;
}

Bubbles.prototype.addBubble = function(name, value) {
	this.hash[name] = value;
}

Bubbles.prototype.showBubble = function(name) {
	var pos = this.findPos(document.getElementById('icon_'+name));
	var div = document.getElementById('div_'+name);
	div.style.left = String(pos[0] + 30) + 'px';
	div.style.top = String(pos[1]) + 'px';
	div.style.display = 'block';
}

Bubbles.prototype.hideBubble = function(name) {
	var div = document.getElementById('div_'+name);
	div.style.display = 'none';
}

Bubbles.prototype.showBubbles = function() {
	for (var name in this.hash) {
		this.showBubble(name);
	}
	if(document.addEventListener)
		document.addEventListener("mouseup", hideBubbles, false);
	else {
		document.attachEvent("onmouseup", hideBubbles);
	}
}

Bubbles.prototype.hideBubbles = function() {
	for (var name in this.hash) {
		this.hideBubble(name);
	}
	if(document.removeEventListener)
		document.removeEventListener("mouseup", hideBubbles, false);
	else {
		document.detachEvent("onmouseup", hideBubbles);
	}

}

var bubbles = new Bubbles();

function hideBubbles() {
		bubbles.hideBubbles();
}
