(function($){
	$.fn.bubbleup = function(options) {
		
		//Amplie as opções padrão do plugin
		var opts = $.extend({}, $.fn.bubbleup.defaults, options);
        var tip = null;


    	return this.each(function() {   
    	
    		//Definir o valor da opção passou por aqui
            var $tooltip = opts.tooltips; 

  			$(this).mouseover(
  	  
    			function () {
            		
            		if($tooltip) {
            		
                		tip = $('<div>' + $(this).attr('alt') + '</div>');
                		tip.css({
							fontFamily: 'Helvetica, Arial, sans-serif',
                			color: '#555555', 
                			fontSize: 12, 
                			fontWeight: 'bold', 
                			position: 'absolute', 
                			zIndex: 100000
                		});
            			
            			tip.remove().css({
            				top: 0, left: 0, 
            				visibility: 'hidden', 
            				display: 'block'
            			}).appendTo(document.body);         
            			//Obter a largura e altura da imagem atual item
            			var position = $.extend({}, $(this).offset(), {
            				width: this.offsetWidth, 
            				height: this.offsetHeight
            			});            			
            			//Obter a largura e altura da ponta do elemento
            			var tipWidth = tip[0].offsetWidth, tipHeight = tip[0].offsetHeight;	           			
                		//Define a posição para a ponta para mostrar corretamente
    					//Posição: superior e centro de imagem   
            			tip.stop().css({
            				top: position.top - tipHeight, 
            				left: position.left + position.width / 2 - tipWidth / 2, 
            				visibility: 'visible'
            			});	
            			tip.animate({
        					top: "-=24",
        				}, 'fast'); 
        			}     			
        			$(this).stop();
        			$(this).css({'z-index' : 100, 'top' : 0, 'left' : 0, 'width' : 35}).animate({
        				left: "-=5",
        				top: "-=5",
                		width: 50
        			}, 'fast');	
    			}
  			).mouseout(
    			function () {
           			if($tooltip) {
                    	tip.remove();
                    }			
    				$(this).stop();
        			$(this).animate({
        				left: 0,
        				top: 0,
                		width: 35
        			}, 'fast', function() {
        					$(this).css({'z-index' : 0});
        				}
        			);
    			}
  			);
    	});
 	};
 	$.fn.bubbleup.defaults = {
		tooltips: false
	}
})(jQuery);
