/**
 * @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
 */
var lastz = 50;
(function ($) {
	$.fn.bubble = function (options) {
		var defaults = {
			'trigger' : '.trigger',
			'popup' : '.popup',
			'distance' : 0,
			'hideDelay' : 10,
			'effectTime' : 250
		};
		
		var settings = $.extend({}, defaults, options);
		var thiswidth = parseInt(this.css("width"));
		thiswidth = isNaN(thiswidth)?0:thiswidth;
		return this.each(function () {
			var hideDelayTimer = null;

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

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

				if (popup.is(':animated, :visible')) 
				{
					return;
				} 
				else 
				{
					lastz++;
					zl = thiswidth;
					zl -= settings.distance;
					zl = zl + 'px';
					//popup.html('<img src="'+trigger.attr("src").replace('thumb_','')+'">');
					$('img',popup).attr('src',trigger.attr("id").replace('thumb_',''));
					popup.css("z-index",lastz);
					popup.css("display", 'block');
					popup.css("bottom",'0px');
					//alert(zl);
					popup.css("right", '0px');
					popup.animate({	opacity: 1,	right: '-=' + settings.distance + 'px' }, settings.effectTime);				
				}
				
			});

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

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




	}
})(jQuery);
