var Akstips = {
	_Move: function(e) {
		var tip = $('akstips_label');
		var mouseX = Event.pointerX(e);
		var mouseY = Event.pointerY(e);
		var tipsize = tip.getDimensions();
		
		// Suivant si la tips dépasse de l'écran on la fait passer de l'autre côté
		if(mouseX+tipsize.width >= document.viewport.getWidth()) tip.style.left = mouseX - tipsize.width + 'px';
		else tip.style.left = mouseX + 'px';
		
		// Suivant si la tips dépasse de l'écran on la fait passer en dessous
		if(mouseY-tip.cumulativeScrollOffset().top-tipsize.height <= 0) tip.style.top = mouseY + 5 + 'px';
		else tip.style.top = mouseY - tipsize.height - 5 + 'px';
	},
		
	_Show: function(text, effect) {
		if(text.suffixe != undefined && text.suffixe == '_form') 
		{
			var tip = '<img src="/js/ajaks/akstips_pointer_top.gif" alt="" class="akstips_pointer_top" />'; 		
		} else {
			var tip = ''; 
			text.suffixe = '_info';
		}
		
		// titre
		if(text.titre != null) 
		{
			tip += '<div class="akstips_titre' + text.suffixe + '">' + text.titre;
			if(text.suffixe == '_form') tip += '<a href="javascript:;" onclick="Akstips._Hide();" title="Fermer" class="akstips_fermer">x</a>';
			tip += '</div>';
		}
		
		// contenu
		tip += '<div class="akstips_content">' + text.html + '</div>';
		
		$('akstips_label').update(tip); // on copie notre texte dans l'élément html
		if(effect == undefined) $('akstips_label').show(); // Si il est cacher (la verif n'est qu'une securité) on le rend visible.
		else new Effect.Appear('akstips_label', {duration: 0.5, to: 1});
	},
		
	_Hide: function(effect) {
		if(effect == undefined) $('akstips_label').hide(); // Si la bulle est visible on la cache
		else new Effect.Fade('akstips_label');
	},
		
	_Form: function(el, text) {
		var elXY = el.cumulativeOffset();
		var elW	  = el.getWidth();
		var elH	  = el.getHeight();
		/*$('akstips_label').style.top = elXY.top + 'px';
		$('akstips_label').style.left = elXY.left + elW + 10 + 'px';*/
		$('akstips_label').style.top = elXY.top + elH + 1 + 'px';
		$('akstips_label').style.left = elXY.left + 'px';
		Akstips._Show({'titre': 'Information', 'html': text, 'suffixe': '_form'}, 'appear');
		new Event.observe(el, 'keypress', function(){ Akstips._Hide('fade'); });
	},
	
	_Load: function() {
		$$('[akstips]').each(function(el) {
			var id = el.getAttribute('akstips');
			new Event.observe(el, 'mousemove', Akstips._Move);
			new Event.observe(el, 'mouseover', function(){ Akstips._Show({'titre': $(id).getAttribute('title'), 'html': $(id).innerHTML}); });
			new Event.observe(el, 'mouseout', function(){ Akstips._Hide(); });				  
		});	
	},
	
	load: function() {
		new Event.observe(window, 'load', function() {
			Akstips._Load();	
		});
	}
}

Akstips.load();