/*
 * jQuery jellytip plugin 1.0
 *
 */
$.fn.jellytip = function(options) {  
	
	var defaults = {
		color: 'green',
		direction: 'right'
	};
	
	var options = $.extend(defaults, options);
	
	var obj = $(this);

   return this.each(function() {  
		var obj = $(this);
		var tooltip = $("#"+options.color+"jellytip_"+options.direction);

		var title = $.trim(obj.attr("title"));
		obj.attr("title", "");
		obj.data("title", title);
		
	
		obj.mousemove(function(e) { 
			if(obj.hasClass("noMore"))
				return;
	
			tooltip.find(".center span").text(obj.data("title"));
			tooltip.fadeIn("fast");

			var winwidth = $(window).width();
			
			var tipwidth = tooltip.find('.line .center').width()+8;
			
			var modifier = (options.direction == 'right') ? 25 : tipwidth-38;
			
			var xpos = ((e.pageX - modifier + tipwidth) < (winwidth-10)) ? (e.pageX - modifier) : (winwidth - tipwidth - 10); // 10 pixel buffer on the right side

			if(xpos < 10) // 10 pixel buffer on the left side
				xpos = 10;
				
			var ypos = 0;
			
			tooltip.css({'position':'absolute', 'top':(e.pageY-42)+'px', 'left':xpos+'px'});

	 	}); // end mousemove
		
		obj.mouseout(function() { tooltip.fadeOut("fast");} );

   });  
};