/*
 * TinyTip 1.0
 *
 * @requires jQuery v1.3.x
 *
 * http://yobird.com
 * http://docs.jquery.com/Plugins/TinyTip
 *
 * Copyright (c) 2009 Sindre Sørhus
 * 
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 */

;(function($) {
	$.fn.tinytip = function(options) {

		opts = $.extend({}, $.fn.tinytip.defaults, options);
		
		return this.each(function() {
			
			var $this = $(this);
			var showTimeout;
			//var hideTimeout;
			
			$this.data('title',$this.attr('title'));
			$this.removeAttr('title');
			
			$body = $('body');
			$tip = $('#tinytip');
			$tipContent = $('#tinytip div');
			if($tip.length == 0){
				$body.append('<div id="tinytip" style="display:none;position:absolute;"><div></div></div>');		
			}
			
			$this.hover(function(event){
				//clearTimeout(hideTimeout);
				$tipContent.html($this.data('title'));
				$body.bind('mousemove', function(event){
					$tip.css({
						top: event.pageY + opts.yOffset,
						left: event.pageX + opts.xOffset
					});
				});
				showTimeout = setTimeout(function(){
					$tip.fadeIn(opts.fadeTime);							  
				}, opts.delay);				 
			}, function(){
				clearTimeout(showTimeout);	
				$body.unbind('mousemove');
				//hideTimeout = setTimeout('$tip.hide()', 0);
				$tip.hide();
			});

		});
	};
	
	$.fn.tinytip.defaults = {
		delay: 100,
		fadeTime: 300,
		yOffset: 10,
		xOffset: 10
	};

})(jQuery);