  function initTooltip() {

    jQuery('.bubble').click(function(evt) {
        /*evt.preventDefault(); /* Pour popup p5005 */ 
    }).simpletip({
        fixed: true,
        hideEffect: 'none',
        offset: [-18, -24],
        onBeforeShow: function() {

            this.update('<div class="tooltipLoader" />');

            var parent = this.getParent();
            
            var id = parent.attr('id');
            if (id === null) {
                this.update('');
                return;
            }

            jQuery.ajax({
                url: basePopupUrl,
                data: { id: id },
                type: 'get',
                simpletipApi: this,
                dataType: 'json',
                error: function(XMLHttpRequest, textStatus, errorThrown) {
                	alert(XMLHttpRequest+' - '+textStatus+' - '+errorThrown);
                },
                success: function(json) {
                	var posleft = '10'; // position horizontale relative
		            var postop = '-24';	// position verticale relative
		            
		            // La taille du tooltip correspond à la moitié de la taille de la frame
		            var tooltipWidth = ($(window).width() / 2) - 15;
		            
		            // On fixe un max
		            if (tooltipWidth > 280) {
                  tooltipWidth = 280;
                }
                // Et un min
                if (tooltipWidth < 160) {
                  tooltipWidth = 160;
                }
                //$(".tooltiptxt").css("width", tooltipWidth);
                
                if (this.simpletipApi.getPos().left > ($(window).width() / 2)) {
		            	
		            	posleft = '-' + (tooltipWidth + 5);  // décalage de la largeur du tooltip
		            	
		            	flechegauche = '';
          				flechedroite = '<div class="tooltipfleched" />';
		            
                } else {
		              
                  posleft = '10';  
		              flechegauche = '<div class="tooltipflecheg" />';
			            flechedroite = '';
		            }
          		
          		  this.simpletipApi.setPos(posleft , postop);
          			
		            if (json.Id !== null) {
                        this.simpletipApi.update(flechegauche + '<div class="tooltiptxt" style="width : ' + tooltipWidth + 'px">' + json.HtmlContents + '</div>' + flechedroite);
                    } else {
                        this.simpletipApi.update(json.Id+'');
                    }
                }
            });
        }
    });

}

jQuery(initTooltip);
