// JavaScript Document

var nvs_footnoteMouseOver = false;
(function($) {
	$.fn.footnotes= function(options) { 
		
		var defaults = {
			offsetX	: 5,
			offsetY	: 5
		};
		
		var options = $.extend(defaults, options);
		
		return this.each(function() {
			$(this).click(function() { this.blur(); return false; });
			$(this).mouseover(_show_footnote);
			$(this).mouseout(_hide_footnote);
		});
		
		function _show_footnote(event) { 
			_instant_hide_footnote();
			
			this.blur();
			
			$('<div></div>').attr({
					id: 'nvs_footnote' 
					})
				.css({
					position: 'absolute',
					display: 'block',
					top: -1000,
					left: -1000
					})
				.appendTo('body').mouseover(_prevent_hide).mouseout(_hide_footnote);
		
			$('<div></div>').attr({
					id: 'nvs_footnote_content'
					})
				.css({
					 position: 'relative'
					})
				.appendTo('#nvs_footnote').mouseover(_prevent_hide);
			
			$("#nvs_footnote_content").html($('#lifootnote_'+$(this).attr('rel')).html());
			if($("#nvs_footnote_content").width() > 300) { 
				newWidth = $("#nvs_footnote_content").width() / $("#nvs_footnote_content").height() * 4;
				if(newWidth > 300) { newWidth = 300; }
				$("#nvs_footnote_content").css({width: newWidth});
			}
				var pageCoords = { top: (event.pageY + options.offsetY), left:  (event.pageX + options.offsetX) } ;
			$("#nvs_footnote").css(pageCoords);
		//	$(document).bind('mousemove', _follow_mouse );			
		}
		
		function _follow_mouse(event) {
			var pageCoords = { top: (event.pageY + options.offsetY), left:  (event.pageX + options.offsetX) } ;
			$("#nvs_footnote").css(pageCoords);
		}
		
		function _hide_footnote() { 
			nvs_footnoteMouseOver = window.setTimeout(function() { _instant_hide_footnote()	}, 500); 
		}
		
		function _instant_hide_footnote() {
			window.clearTimeout(nvs_footnoteMouseOver);	
			$(document).unbind('mousemove',_show_footnote._follow_mouse );		
			$('#nvs_footnote').remove();
		}
		
		function _prevent_hide() {
			window.clearTimeout(nvs_footnoteMouseOver);
			nvs_tooltipMouseOver = false; 
		}
	}
	
	
})(jQuery);


jQuery(function($) {
				
	$('#footnotes').hide();	
	$('#printbutton').click(function() { window.print(); return false; });
	$('.footnote').footnotes();
});

