if(!ANAEMA) var ANAEMA = {};

ANAEMA.Anatips = Class.create({
	objTip:   undefined,
	tipsArray:  [],

	initialize: function() {	
		this.tipsArray = [];		
		objBody = $$('body')[0];
		this.objTip = objBody.appendChild(Builder.node('div',{id:'anatips_tip'}));
		this.setupTooltips();		
	},	
	
	setupTooltips: function() {
		me = this;
		cnt = 0;
		$$('.anatips').each(function(el){				
			if(el.title && el.title.length > 0) {				
				el.observe('mouseover', (function(event) { event.stop; me.handleMouseOver(event) }).bind(this));
				el.observe('mousemove', (function(event) { event.stop; me.handleMouseMove(event) }).bind(this));
				el.observe('mouseout',  (function(event) { event.stop; me.handleMouseOut(event) }).bind(this));
				me.tipsArray[cnt] = el.title;
				el.tip_num = cnt++;
				el.removeAttribute('title');
			}
		})		
	},		
	
	handleMouseOver: function(event){
		target = event.findElement('.anatips');
		if (target) {
			this.objTip.innerHTML = this.tipsArray[target.tip_num];
			this.objTip.style.visibility = "visible";
			image = event.findElement('.anatips img');
			if(image) image.alt = '';
		}
	},
	
	handleMouseMove: function(event){
		target = event.findElement('.anatips');
		if (target) {
			this.objTip.style.left = (event.pointerX() + 20) + 'px';
			this.objTip.style.top = (event.pointerY() + 20) + 'px';
		}
	},
	
	handleMouseOut: function(event){
		this.objTip.style.visibility = "hidden";
	}
	
});

document.observe('dom:loaded', function () { ANAEMA.tips = new ANAEMA.Anatips(); });