/**
 * @author Remy Sharp
 * @date 2008-03-27
 * @url http://jqueryfordesigners.com/coda-popup-bubbles/
 * @license Creative Commons License - ShareAlike http://creativecommons.org/licenses/by-sa/3.0/
 *
 * See URL for markup examples and screencast
 *
 * Added 'showDelay' for brita
 */

(function ($) {
	$.fn.bubble = function (options) {
		var defaults = {
			'trigger' : '.trigger',
			'popup' : '.popup',
			'distance' : 10,
			'hideDelay' : 500,
			'effectTime' : 250,
			'showDelay'  : 300		// showDelay added specifically for brita
		};
		
		var settings = $.extend({}, defaults, options);
		
		return this.each(function () {
			var hideDelayTimer = null;

			var trigger = $(settings.trigger, this);
			var popup = $(settings.popup, this);
			
			var readyToShow = false;

			$([trigger.get(0), popup.get(0)]).mouseover(function () {
				if (hideDelayTimer) clearTimeout(hideDelayTimer);

				readyToShow = true;

				setTimeout(function() {
					if (popup.is(':animated, :visible') || !readyToShow) {
						return;
					} else {
						popup.css({
							display: 'block',
							bottom: 130,
							left: -85
						}).animate({
							opacity: 1,
							bottom: '-=' + settings.distance + 'px'
						}, settings.effectTime);
					}
				}, settings.showDelay);
			}).mouseout(function () {
				if (hideDelayTimer) clearTimeout(hideDelayTimer);

				readyToShow = false;

				hideDelayTimer = setTimeout(function () {
					hideDelayTimer = null;
					popup.animate({
						bottom: '-=' + settings.distance + 'px',
						opacity: 0
					}, settings.effectTime, 'swing', function () {
						popup.css('display', 'none');
					});		
				}, settings.hideDelay);
			});
		});
	}
})(jQuery);