

/**
 * Ovos Map
 * 
 * @author Marcin Gil <mg@ovos.at>
 */
$(function()
{
	$('#ovos-map area').mapBubble
	({
		areaEl: '#ovos-map-area',
		areaId: 'area',
		bubbleId: 'bubble',
		visibleBubbles: ['ovos'],
		closeButtonCls: '.bubble-close-button',
		fadeInSpeed: 'fast',
		fadeOutSpeed: 'fast'
	});
});

/**
 * Map bubbles
 * 
 * @author Marcin Gil <mg@ovos.at>
 */
(function($)
{
	$.fn.mapBubble = function(options){
		var opts = $.extend({}, $.fn.mapBubble.defaults, options);
	
		var self = this;
		var $this = $(this);
		
		return $this.each(function()
		{
			var idParts = $(this).attr('id').split('-');
			var area = idParts[0];
			var id = idParts[1];
			
			if(area == opts.areaId)
			{
				var el = $('#'+ opts.bubbleId + '-' + id);
					
				if($.inArray(id, opts.visibleBubbles) == -1)
				{
					el.css
					({
						opacity: 0
					});
				}
				else
				{
					$(opts.closeButtonCls, el).one('click', function()
					{
						el.fadeTo(opts.fadeOutSpeed, 0, function(){ el.hide(); });
					});
				}
				
				$(this).bind('mouseenter', function()
				{
					el.show().fadeTo(opts.fadeInSpeed, 1, function()
					{
						if($.inArray(id, opts.visibleBubbles) == -1)
						{
							el.one('mouseleave', function()
							{
								el.fadeTo(opts.fadeOutSpeed, 0, function(){ el.hide(); });
							});
						}
						else
						{
							$(opts.closeButtonCls, el).one('click', function()
							{
								el.fadeTo(opts.fadeOutSpeed, 0, function(){ el.hide(); });
							});							
						}
					});
				});
			}
		});
	}
	
	$.fn.mapBubble.defaults = {
		areaEl: '',
		areaId: '',
		bubbleId: '',
		closeButtonCls: '',
		visibleBubbles: [],
		fadeInSpeed: 'fast',
		fadeOutSpeed: 'fast'
	};
})(jQuery);

/**
* Below is <a> version
*/

/**
 * Ovos Map
 * 
 * @author Marcin Gil <mg@ovos.at>
 */
/*
$(function()
{
	$('#ovos-map-container').mapBubble
	({
		visibleBubbles: ['ovos'],
		fadeInSpeed: 'fast',
		fadeOutSpeed: 'fast'
	});
});
*/
/**
 * Map bubbles
 * 
 * @author Marcin Gil <mg@ovos.at>
 */
/*
(function($)
{
	$.fn.mapBubble = function(options)
	{
		var opts = $.extend({}, $.fn.mapBubble.defaults, options);
		
		return $(this).each(function()
		{
			var self = this;
			var $this = $(this);
			
			var img = $('img', self);
			var map = $('map[name='+ img.attr('usemap').substring(1) +'] area');
			
			console.log(map);
			
			$(opts.bubbleCls, self).each(function()
			{
				console.log(this);
				var id = $(this).attr('id').split('-')[1];
				var el = $(this);
				if($.inArray(id, opts.visibleBubbles) == -1)
				{
					el.css
					({
						display: 'block',
						opacity: 0
					});
				}
				else
				{
					map.one('mouseenter', function()
					{
						el.fadeTo(opts.fadeOutSpeed, 0, function(){ el.hide(); });
					});
				}
			});
			
			$(opts.invokerCls, this).each(function()
			{
				var id = $(this).attr('id').split('-')[1];
				var el = $('#bubble-' + id, self);
				
				$(this).bind('mouseenter', function()
				{
					console.log(this);
					el.show().fadeTo(opts.fadeInSpeed, 1, function()
					{
						map.one('mouseenter', function()
						{
							el.fadeTo(opts.fadeOutSpeed, 0, function(){ el.hide(); });
						});
					});
				});	
			});
		});
	}
	
	$.fn.mapBubble.defaults = {
		invokerCls: 'a.invoker',
		bubbleCls: 'div.bubble',
		visibleBubbles: [],
		fadeInSpeed: 'fast',
		fadeOutSpeed: 'fast'
	};
})(jQuery);
*/