(function ($) {
	$.fn.embedSWF = function (settings)
	{
		return this.each(function (i) {
			
			var $self = $(this);
			
			if(window.flashembed != undefined && $self.data('embed') !== true && $self.data('src') != undefined)
			{
				var id = $self.attr('id') == undefined ? 'flashembed-' + parseInt(i+1) : $self.attr('id') + '-swf';
				
				var defaults = {
					src: $self.data('src'),
					id: id,
					width: '100%',
					height: '100%',
					version: [9,0],
					wmode: 'transparent',
					cachebusting: true,
					onFail: function () {
						$self.find('.no-flash').show();
					}
				};
				
				$.extend(defaults, settings || {});
				
				var vars = $self.data('vars');
				var flashVars = {};
				
				if(vars != undefined)
				{
					$self.removeAttr('data-vars');
					$.each(vars.split('&'), function (i, item) {
						
						var itemData = item.split('=');
						
						flashVars[itemData[0]] = itemData[1];
					});
				}
				
				flashVars = $.extend({}, $.fn.embedSWF.flashVars, flashVars || {});
				
				flashembed(this, defaults, flashVars);
				
				$self.data('embed', true).removeAttr('data-src');
			}
			else if(window.flashembed == undefined)
			{
				//$.error('O plugin flashembed não foi adicionado.');
			}
			else if($self.data('src') == undefined)
			{
				//$.error('O atributo data-src do elemento não foi definido.');
			}
		});
		
	};
	
	$.fn.embedSWF.flashVars = {
		baseURL: location.protocol + '//' + location.host + location.pathname
	};
	
})(jQuery);
