if(!SBTooltips) var SBTooltips = {};

jQuery.extend(SBTooltips, {

    TIPS:	[],
    ZINDEX:	50,

	tooltips:	function(elem, options) {
        this._index = SBTooltips.TIPS.push(this) - 1;
        this._element = elem;
        this._options = options;

        this.init();
	}
});

jQuery.fn.sbToolTips = function(options) {

	SBTooltips.TIPS = [];
	SBTooltips.ZINDEX = 50;

	options = jQuery.extend({
		wrapperSelector:	'span.tips',
		wrapper:			'<span class="ss_sprite ss_help tips"></span>',
		speed:				'normal'
	}, options);

	return this.each( function() {
		new SBTooltips.tooltips(jQuery(this), options);
	} );
};

SBTooltips.tooltips.prototype.openToolTips = function() {
	for(instance in SBTooltips.TIPS) {
		if(instance != this._index && SBTooltips.TIPS[instance]._element) {
			SBTooltips.TIPS[instance]._element.hide();
		}
	}
	this._element.css('z-index', SBTooltips.ZINDEX++).fadeIn(this._options.speed);
};

SBTooltips.tooltips.prototype.closeToolTips = function() {
	this._element.fadeOut(this._options.speed);
};

SBTooltips.tooltips.prototype.init = function() {
	// Hide the tooltips
	this._element.hide();
	// Add extra markup
	if(this._element.parent(this._options.wrapperSelector).length == 0) {
		this._element.wrap(this._options.wrapper);
	}
	// Store the icon
	this._icone = this._element.parent(this._options.wrapperSelector);

	// Bind events on icon
	var index = this._index;
	this._icone.hover(
		function() {	SBTooltips.TIPS[index].openToolTips();		},
		function() {	SBTooltips.TIPS[index].closeToolTips();	}
	);
};

// Transforme tous les span.quiet dans les label des formulaires en tooltips
initToolTips = function() {
	$('span.help').sbToolTips();
}
$(function() { initToolTips(); } );