/*
 * 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.setupTooltips = function () {
	// for all the <i> tags that have the class tooltip
	$j("i.tooltip").each(function(e){
		var text = $j(this).html();
		
		// these are the defined terms. if we have <i>material</i> then the title will get replaced by the case below.
		switch( text.toLowerCase() ) {
			case "rights holder":
			case "rights holders":
				$j(this).attr("title","The individual or entity that holds or controls certain intellectual property rights in an input, such as copyright.");
				break;
			case "material":
				$j(this).attr("title","The publication or other work you wish to review using this GILF Licensing Review process.");
				break;
			case "input":
			case "inputs":
				$j(this).attr("title","Content that is not 'Original Content' that has been incorporated from another source or sources.");
				break;
			case "original content":
				$j(this).attr("title","Content that is unique and original to the material. It is content that has not been incorporated from another source or sources.");
				break;
		}
	});
}

this.tooltip = function(){	
	/* CONFIG */		
		xOffset = 5;
		yOffset = 22;
		// these 2 variable determine popup's distance from the cursor
		// you might want to adjust to get the right result		
	/* END CONFIG */		
	$j("i.tooltip").hover(
	function(e) {
		this.t = this.title;
		this.title = "";									  
		$j("body").append("<p id='tooltip' style='margin-right:15px'>"+ this.t +"</p>");
		$j("#tooltip")
			.css("top",(e.pageY + yOffset) + "px")
			.css("left",(e.pageX + xOffset) + "px")
			.show();//("fast");
    },
	function(){
		this.title = this.t;		
		$j("#tooltip").remove();
    });	
	$j("i.tooltip").mousemove(function(e){
		var iebody=(document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
		var docwidth=(window.innerWidth)? window.innerWidth-15 : iebody.clientWidth-15
		var docheight=(window.innerHeight)? window.innerHeight-18 : iebody.clientHeight-15
		var twidth=$j("#tooltip").width();
		var theight=$j("#tooltip").height();
		var tipx=e.pageX+xOffset
		var tipy=e.pageY+yOffset
		tipx=(e.clientX+twidth>docwidth)? tipx-twidth-(2*xOffset) : tipx //account for right edge
		tipy=(e.clientY+theight>docheight-yOffset)? tipy-theight-(2*yOffset) : tipy //account for bottom edge

		$j("#tooltip").css({left: tipx, top: tipy});
	});			
};

// starting the script on page load
$j(document).ready(function(){
	setupTooltips();
	tooltip();
});


