/*
 * Tooltip script 
 * powered by jQuery (http://www.jquery.com)
 * 
 * written by Alen Grakalic (http://cssglobe.com)
 * 
 * for more info visit http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery
 *
 */
 
	this.tooltip = function(){	

		$(".bottone").each(function(){
			this.tip = this.title;
			this.title='';
		});
		
		/* CONFIG */		
			xOffset = 10;
			yOffset = 20;	
			tolerance = 5; //tolleranza dal bordo dello schermo	
			// these 2 variable determine popup's distance from the cursor
			// you might want to adjust to get the right result		
		/* END CONFIG */		
		$(".bottone").mouseover(function(e){											  
			
			tooltip=document.createElement('div');
			tooltip.id = 'tooltip';
			$(tooltip).html(this.tip)
			width = parseInt($(tooltip).css('width')) + parseInt($("#tooltip").css('padding-left')) + parseInt($("#tooltip").css('padding-right')) + tolerance;
			
			posX = e.pageX + yOffset;

			if(posX + width >= $(window).width()){
				posX -= width;
			}

			$("body").append(tooltip);
			$("#tooltip")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(posX) + "px")
				.css("opacity",0.8)
				.fadeIn("fast");
	    });
	    
		$(".bottone").mouseout(function(e){
			$("#tooltip").remove();
	    });	
	    
		$(".bottone").mousemove(function(e){
			
			posX = e.pageX + yOffset;
			
			width = parseInt($("#tooltip").css('width')) + parseInt($("#tooltip").css('padding-left')) + parseInt($("#tooltip").css('padding-right')) + tolerance;
			
			if(posX + width >= $(window).width()){
				posX -= width + 2*yOffset;
			}

			$("#tooltip")
				.css("top",(e.pageY - xOffset) + "px")
				.css("left",(posX) + "px");
		});			
	};

