;(function($) {
	$.fn.video = function(options) {
		var o = $.extend(true, {}, $.fn.video.defaults, options);
		return $(this).each(function() {
			var $self = $(this);
			var $vid = $('<div>', {'class': 'video-player'});
			$vid.flash(
				$.fn.extend(true, {},
					{
						width:		$self.width(),
						height:		$self.height()
					},
					o.extract($self.attr('href'))
				)
			);
			$self.addClass('active').after($vid);
		});
	};
	$.fn.video.defaults = {
		filters: {
			youtube: {
				re: /^.+?youtube\.com\/watch\?v=([^&]+)$/,
				replace: 'http://www.youtube.com/v/$1',
				process: function(href, regs) { return { src: href };},
			},
			vimeo: {
				re: /^.+?vimeo\.com\/(.+)$/,
				replace: 'http://vimeo.com/moogaloop_local.swf',
				process: function(href, regs) {
					return {
						src: href,
						flashvars: {clip_id: regs[1], server: 'vimeo.com'}
					}
				}
			}
		},
		extract: function(href) {
			var h;
			for (var p in this.filters) {
				var f = this.filters[p];
				if (null !== (h = f.re.exec(href) ))
					return f.process(href.replace(f.re, f.replace), h);
			}
			return href;
		}
	};
})(jQuery);
