/*
tooltip.js
	Inserts a tooltip div replacing its
	content with the title attribute from
	the markup. If the tooltip comes in
	contact with the edge of the page, it
	changes its width to not get out of
	sight.
By Luca De Angelis
	lucaDOTdeangelisATgmailDOTcom
	For Elettra Progetti e Servizi S.p.A.
*/

var xOffset = -15;
var yOffset = 30;

this.tooltip = function(){
	// Removing the title from the element and placing it into the div
	$(".tooltip").hover(function(e){
		// Mousein
		this.t = this.title
		.replace("Link esterno", "<b>Link esterno</b>").replace("External link","<b>External link</b>")
		.replace("Documento protetto", "<b>Documento protetto</b>").replace("Protected document","<b>Protected document</b>")
		.replace("Curriculum Vitae", "<b>Curriculum Vitae</b>")
		.replace("Download", "<b>Download</b>")
		.replace("Send us your CV","<b>Send us your CV</b>")
		.replace("Offerte di Lavoro","<b>Offerte di Lavoro</b>").replace("Open Vacancies","<b>Open Vacancies</b>")
		.replace("Servizio RSS","<b>Servizio RSS</b>").replace("RSS Service","<b>RSS Service</b>");
		this.title = "";
		$("#tooltip").remove();
		// Creating the tooltip
		$("body").append("<div id='tooltip'><img src='Img/Angolo_tooltip.gif' />" + this.t + "</div>");
		// Positioning it
		tooltipPosition(e);
		// Showing it
		$("#tooltip").fadeIn("fast");
	},
	function(e){
		// // Resetting the title on Mouseout
		this.title = this.t.replace("<b>","").replace("</b>","");
		$("#tooltip").fadeOut("fast");
	})
	.mousemove(function(e){
		tooltipPosition(e);
	})
	.click(function(){
		// Resetting the title on Click
		this.title = this.t.replace("<b>","").replace("</b>","");
		$("#tooltip").fadeOut("fast");
	});
};

// Function that place the tooltip near the mouse pointer
this.tooltipPosition = function(e){
	$("#tooltip")
		.css("left", e.pageX + xOffset + "px")
		.css("top", e.pageY - yOffset - $("#tooltip").height() + "px")
		.find("img").css("top", $("#tooltip").height() + 10 + "px");
}

// Starting the script on page load
$(document).ready(function(){
	tooltip();
});

