/*
	jQuery Tooltip Plugin
	(C) 2009 Matthias Schuetz - http://matthiasschuetz.com
	------------------------------------------------------
	
	jquery.tooltip1.js - Tooltip-Inhalt aus "title"-Text
	
	------------------------------------------------------
	
	[ Benutzung ]
	
	$(".klasse, #id").tooltip({
		hintergrund: "#FFFFFF",
		schriftfarbe: "#000000",
		rand: "2px #CCCCCC solid",
		eckenradius: 8,
		zeit: 400
	});
	
	------------------------------------------------------
*/

$.fn.tooltip = function(optionen){
	optionen = $.extend({
		eckenradius: 8,
		alpha: 0.9
	}, optionen);
	
	function zeigeTooltip(evt, inhalt, classname){
		$("<div>", {
			id: "tooltip",
			"class": classname,
			css: {
				position: "absolute",
				left: evt.pageX + 20,
				top: evt.pageY + 20,
				display: "none",
				"-moz-border-radius": optionen.eckenradius,
				"-webkit-border-radius": optionen.eckenradius
			},
			html: inhalt
		})
		.appendTo("body")
		.show()
		.fadeTo(0, optionen.alpha);
	}

	$(this).each(function(){
		var inhalt = $(this).attr("title");
		var test = inhalt.search(/\[/g);
		if (test == -1) {
			var classname = "ezTooltip";
		} else {
			inhalt = inhalt.replace(/\[/g, "<");
			inhalt = inhalt.replace(/\]/g, ">");
			var classname = "ezToolinfo";
		}
		
		$(this).attr("title", "");
		$(this).bind({
			mouseenter: function(evt){
				if ($("#tooltip").css("opacity") != 0) {
					$("#tooltip").stop().remove();
				}
				
				zeigeTooltip(evt, inhalt, classname);
			},
			mouseleave: function(){
				$("#tooltip").remove();
			},
			mousemove: function(evt){
				$("#tooltip").css({
					left: evt.pageX + 20,
					top: evt.pageY + 20
				});
			}
		});
	});
}
