/*
 * jQuery aHoverTip v1.0.1
 * Copyright 2011 Jiří Alke, http://www.alcado.cz
 * Licensed under MIT License
 * http://www.alcado.cz/license/mit
 *
 */

(function($) {

	$.fn.aHoverTip = function(options) {

		var defaults = {
			width : 220, // tooltip width (px)
			delay : 200, // tooltip animation delay time (ms)
			animate : 10, // tooltip vertical animation (px)
			color : "#ffffff" // tooltip text color
		};

		var options = $.extend(defaults, options);

		aTip = function() {
			var tipBody = "<div class='tip'><div class='tipTop'></div><div class='tipText'></div><div class='tipBottom'></div></div>";
			return tipBody;
		}

		$("body").prepend(aTip());

		$(this).each(function() {

			var $this = $(this);
			var tip = $('.tip');
			var tipText = $('.tip .tipText')

			var aTitle = this.title;
			this.title = "";

			var offset = $this.offset();
			var aLeft = offset.left;
			var aTop = offset.top;
			var aWidth = $this.innerWidth();
			var aHeight = $this.innerHeight();

			$this.hover(function() {
				tipText.html(aTitle);
				var ax = aTop - tip.height() - 1 - defaults.animate + "px";
				var ay = aLeft + (aWidth / 2) - (defaults.width / 2) + "px";
				tip.css({"top" : ax, "left" : ay, "color": defaults.color});
				tip.css("opacity", 0).show(0).stop().animate({"top" : "+=" + defaults.animate, "opacity" : 1}, defaults.delay);
			}, function() {
				tip.stop().animate({"opacity" : 0}, defaults.delay).hide(0);
			});

		});

	};

})(jQuery);

