/*
	A jQuery plugin to display a magnifier tooltip that moves with the mouse pointer.
	The tooltip content is copied from the element that was used to trigger it.
*/

(function($){
	var tweak = {
		x: -10,
		y: -30
	}
	
	var tip = null;
	
	
	function format(html){
		var output = html.replace(/^\s+|\s+$|<br>/g, "");
		return output;
	}
	
	function moveTip(event){
		if(tip != null){
			tip.clearQueue();
			
			var mouse = {
				x: event.pageX,
				y: event.pageY
			};
		
			var css = {
				"left" : mouse.x - (tip.width() / 2) + tweak.x + "px",
				"top" : mouse.y - tip.height() + tweak.y + "px"
			};
			
			tip.css(css);
		}
	}
	
	$.fn.tip = function(emtSelector, options){
		if(typeof(options) == 'object'){
			$.extend(tweak, options);
		}
	
		tip = $(emtSelector);
		
		$(document).mousemove(function(event){
			moveTip(event);
		});
		
		$(this).each(function(){
			$(this).mouseenter(function(event){
				$(this).addClass("active");
				tip.html($(this).attr('alt'));
				tip.show();
				moveTip(event);
			});
			
			$(this).mouseleave(function(){
				$(this).removeClass("active");
				tip.hide();
			});
		});
	}
})(jQuery);
