/**
 * jQuery simpleTooltip plugin 
 *
 * @author Marius ILIE (http://dev.mariusilie.net) / Improved by Aamir Afridi (http://www.aamirafridi.com - info@aamirafridi.com)
 * @date 2009-08-06
 * @example $("link").simpletooltip({html : 'My Tooltip', mouseOffset.x : 10 , mouseOffset.y : 12})
 * @example $("link").simpletooltip({ opacity : 0.8, css : { 'padding' : '8px' , 'border' : '2px solid #ccc' } })
 * @desc create a tooltip effect for any html element's title attribute or any text provided
 *
 * @name simpletooltip
 * @type jQuery
 * @param String - html - custom text which will overwrite the text in element's title attribute
 * @param String - errorText - text which will appear if there is no title attribute found or html provide to the plugin otherwise leaving this empty will diable the plugin
 * @param Number - cornerRadius - the radius of the round corner of the tooltip. Work only on Firefox 3+ and Webkit-base browsers
 * @param String - cssClass - if provided, It will overwrite any css provided to the plugin
 * @param Number - opacity - the transparency of the tooltip. From 0.0 to 1. Should work on IE but haven't tested
 * @param String - fadeSpeed - the animation speed of the tooptip to fadeIn
 * @param Number  - mouseOffset.x - the position of the tooltip on x-axis
 * @param Number  - mouseOffset.y - the position of the tooltip on y-axis
 * @param Array  - css - css properties will be applied on the tooltip
 * @cat Plugin
 */



(function($,options){ $.fn.simpletooltip = function(){
	var	 o = $.extend({}, $.fn.simpletooltip.defaults, options);
	return this.each(function() {			
		var st=$('<div>&nbsp;</div>');	
				st.css($.fn.simpletooltip.defaults.css);	  
		var text = ($(this).attr("title")!='') ? $(this).attr("title") : o.errorText, st;
		if(o.html=='' && text=='') return;
		$(this).hover(function(e){
			$(this).attr("title", "");
			var tipX = e.pageX + o.mouseOffset.x,
				tipY = e.pageY + o.mouseOffset.y;
				  st = $('<div>&nbsp;</div>')
					.appendTo('body')
					.html(($.trim(o.html)!='') ? o.html : text);
				st.css({'position':'absolute','z-index':9900,'display':'none','-moz-border-radius'	:o.cornerRadius,'-webkit-border-radius'	:o.cornerRadius,'left':tipX,'top':tipY+o.css});
				
				st.css($.fn.simpletooltip.defaults.css);
			
				if($.trim(o.cssClass)!='') st.addClass(o.cssClass)
				if(o.css!='') st.css(o.css);
				
		}, function(){
			st.remove();
			$(this).attr("title", text);
		})
		.mousemove(function(e){
			st.css($.fn.simpletooltip.defaults.css);
			var tipX = e.pageX + o.mouseOffset.x,
				tipY = e.pageY + o.mouseOffset.y,
				tipWidth = st.outerWidth(true),
				tipHeight = st.outerHeight(true);
			if(tipX + tipWidth > $(window).scrollLeft() + $(window).width()) tipX = e.pageX - tipWidth;
			if($(window).height()+$(window).scrollTop() < tipY + tipHeight) tipY = e.pageY - tipHeight;
			st.css({'left':tipX,'top':tipY}).fadeIn(o.fadeSpeed);
		});
	 });
	}
	
	$.fn.simpletooltip.defaults = {
		html		: '',
		errorText	: '<b>Error:</b><br />No title attribute found<br />And no Html provide to the plugin.', //Leave it empty which will show nothing
		cornerRadius: 5, 	
		cssClass	: 'ui-state-default',
		opacity		: 0.9,
		fadeSpeed	: 'fast',
		mouseOffset: {
						x : 30,
						y : -90
					  },
		css			: {
						'opacity'	: 0.9,
						'filter':'alpha(opacity = '+90+')',
						'padding'	: 7,
						'background-color': '#F2F3F5',
						'border'	: '1px solid #A6A7AB',
						'width'		: '340px',
						
						'font-size'	: '12px'
					  }
	};
	
})(jQuery);


