/**
 * 
 * @name     Bapro_Tooltip
 * @author   Sam Collett (http://www.texotela.co.uk)
 * @author   Lukasz Muchlado (http://bapro.pl)
 * @example  $("a[@title]").Bapro_Tooltip();
 *
 */
$.fn.Bapro_Tooltip = function(){
	/*showw = function(){
		alert('ok');
	};*/
	this.mouseover(
		function(e){
			if((!this.title && !this.alt) && !this.tooltipset) return;
			// get mouse coordinates
			// based on code from http://www.quirksmode.org/js/events_properties.html
			
			var mouseX = e.pageX || (e.clientX ? e.clientX + document.body.scrollLeft : 0);
			var mouseY = e.pageY || (e.clientY ? e.clientY + document.body.scrollTop : 0);
			mouseX += 9;
			mouseY += 21;
//			this.showw();
			// if there is no div containing the tooltip
			if(!this.tooltipdiv){
				// create a div and style it
				var div = document.createElement("div");
				this.tooltipdiv = div;

				div.id = 'bapro_tooltip';
				
				$(div).css({
					position: "absolute"
				})
				
				// add the title/alt attribute to it
				.html((this.title || this.alt));
				this.title = "";
				this.alt = "";
				$("body").append(div);
				this.tooltipset = true;
			}
			
			$(this.tooltipdiv).show()/*.css({left: mouseX + "px", top: mouseY + "px"})*/;
			
		}
	).mouseout(
		function(){
			if(this.tooltipdiv){
				$(this.tooltipdiv).hide();
			}
		}
	).mousemove(
		function(e){
			if(this.tooltipdiv){
				var mouseX = e.pageX || (e.clientX ? e.clientX + document.body.scrollLeft : 0);
				var mouseY = e.pageY || (e.clientY ? e.clientY + document.body.scrollTop : 0);
				mouseX += 9;
				mouseY += 21;
//				var mouseX = this.getX(e) + 20;
				$(this.tooltipdiv).css({left: mouseX + "px", top: mouseY + "px"});
			}
		}
	);
	return this;
}