
this.glossary = function() {    
	this.xOffset = 10; // x distance from mouse
	this.yOffset = 50; // y distance from mouse       
	
	$(".glossary").unbind().click(    
		function(e) { 
			this.t = $(this).text(); 
			
			$.get("/glossary-lookup.php", { key: this.t }, function(data){ 
		
				$('body').append( '<p id="glossbox">' + data + '</p>' );
				
				this.cx = $('p#glossbox').width();
				this.cxDoc = $(document).width();
				if( (e.pageX + this.cx + 60) > this.cxDoc ) { 
					this.left = e.pageX - this.cx - xOffset;
				} else {  
					this.left = e.pageX + xOffset;
				}

				this.cy = $('p#glossbox').height();
				this.top = e.pageY - this.cy - yOffset; 
				if( this.top < 20 ) {
					this.top = e.pageY + 20;
				}
				
				$('p#glossbox').css("top", this.top+"px").css("left", this.left+"px").fadeIn("slow"); 
			});
		}
	).mouseleave(
		function(e) { 
			$("p#glossbox").fadeOut("slow").remove();
		}
	);            
	
};

jQuery(document).ready(function($){glossary();}) 
