/*
* Mag Studio - Tooltip/Cooltip :)
* @Author: Alexander Gavazov
* @Site: www.creative.bg & www.studio.bg
*/

var Cooltip = function(node, text)
{
	this.node = node;
	this.text = text;
	this.text = this.text.replace(/ /g, '&nbsp;');
	this.tooltip = new Element('DIV', {style: 'position: absolute; z-index: 99999; top: -1000px; left: -1000px'});

	this._offsetLeft = 15;
	this._offsetRight = 5;

	this.setBehaviour();
}

Cooltip.prototype.setBehaviour = function()
{
	this.node.onmouseover = this.show.bind(this);
	this.node.onmouseout = this.hide.bind(this);
	this.node.onmousemove = this.move.bind(this);
}

Cooltip.prototype.show = function()
{
	var source = '<div class="tooltip_container">'
	+ '<div class="wall"></div>'
	+ '<div class="content">'
	+ this.text
	+ '</div>';
	+ '</div>';


	this.tooltip.update(source)
	/*
	if(!Prototype.Browser.IE6)
	{
		Opacity.set(this.tooltip, 90);
	}
	*/
	document.body.appendChild(this.tooltip);
	var content = $$('.tooltip_container .content').first();
	var c_width = this.text.length*5;
//	c_width = c_width > 80 ? 80 : c_width;
//	content.setStyle({width: (c_width)+'px'});

}

Cooltip.prototype.hide = function()
{
	this.tooltip.remove();
}

Cooltip.prototype.move = function(event)
{
	if(!event)
	{
		var event = window.event;
	}

	var mouseX = event.clientX + document.documentElement.scrollLeft;
	var mouseY = event.clientY + document.documentElement.scrollTop;

	this.tooltip.style.left = mouseX + this._offsetLeft + 'px';
	this.tooltip.style.top = mouseY + this._offsetRight + 'px';
}

Event.observe(window, 'load', function() {
	$$(".Cooltip").each(function(node) {
		if(node.title)
		{
			new Cooltip(node, node.title);
			node.removeAttribute("title");
		}
	});
});