/*
 * jqPLTooltip
 * by Piotr Łojewski piotr.l@aginus.pl
 *
 *
 *
Wywołanie:
 
$(document).ready(function() {
	$('div.menu ul li a').jqPLTooltip({
		tekst: 'kliknij, aby powiększyć',
		gora: -35,
		lewa: -60,
		title: false,
		center: true,
		przezroczystosc: 0.80
	});
});

CSS:

div.etykieta {
	position: absolute;
}
******************************************** */
 
(function($){
		  
	$.fn.jqPLTooltip = function(options){

		var ustawienia = $.extend({
			tekst: 'kliknij, aby powiększyć',
			gora: -35,
			lewa: -60,
			title: false,
			center: true,
			przezroczystosc: 0.80
		}, options);
		
		return this.each(function(){
								  
		var element = $(this);
		this.t = this.title;
								  
			if (ustawienia.title) {
				
				if (!this.t == '') {
				
					$('body').append('<div class="etykieta" rel="' + this.t + '">' + this.t + '</div>');
					$('div.etykieta').hide();
					var szerokosc = $('div[rel="' + this.t + '"]').outerWidth();
					
					element
						.mouseenter(function(){
							$('div[rel="' + this.t + '"]:first').fadeTo("fast", ustawienia.przezroczystosc);
							this.title = "";
						})
						.mouseleave(function(){
							$('div[rel="' + this.t + '"]').hide();
							this.title = this.t;
						})
						.click(function(){
							this.title = this.t;
						});
					if (ustawienia.center) {
						element
							.mousemove(function(e){
								$('div[rel="' + this.t + '"]:first').css({
									top: (e.pageY + ustawienia.gora) + "px",
									left: (e.pageX - szerokosc/2) + "px"
								});
							})
					} else {
						element
							.mousemove(function(e){
								$('div[rel="' + this.t + '"]:first').css({
									top: (e.pageY + ustawienia.gora) + "px",
									left: (e.pageX + ustawienia.lewa) + "px"
								});
							})
					}
					
				}
				
			} else if (ustawienia.tekst) {
				
				$('body').append('<div class="etykieta" rel="' + ustawienia.tekst + '">' + ustawienia.tekst + '</div>');
				$('div.etykieta').hide();
				var szerokosc = $('div[rel="' + ustawienia.tekst + '"]').outerWidth();
				
				element
					.mouseenter(function(){
						$('div[rel="' + ustawienia.tekst + '"]:first').fadeTo("fast", ustawienia.przezroczystosc);
						this.title = "";
					})
					.mouseleave(function(){
						$('div[rel="' + ustawienia.tekst + '"]').hide();
						this.title = this.t;
					})
					.click(function(){
						this.title = this.t;
					});
				if (ustawienia.center) {
					element
						.mousemove(function(e){
							$('div[rel="' + ustawienia.tekst + '"]:first').css({
								top: (e.pageY + ustawienia.gora) + "px",
								left: (e.pageX - szerokosc/2) + "px"
							});
						})
				} else {
					element
						.mousemove(function(e){
							$('div[rel="' + ustawienia.tekst + '"]:first').css({
								top: (e.pageY + ustawienia.gora) + "px",
								left: (e.pageX + ustawienia.lewa) + "px"
							});
						})
				}
			
			}

		});

	};

})(jQuery);
