var embeded_code = "<object width=\"320\" height=\"265\"><param name=\"allowFullScreen\""+
					"value=\"true\"/><param name=\"wmode\" value=\"transparent\"/><param "+
					"name=\"movie\" value=\"{{ url }}\"/><embed src=\"{{ url }}\" width=\"320\" "+
					"height=\"265\" allowFullScreen=\"true\" type=\"application/x-shockwave-flash\" "+
					" wmode=\"transparent\"></embed></object>";

var codecs = {
	'youtube': {
		'regexp': /http:\/\/(www\.|\w{2}\.|)youtube\.com\/watch\?v=([\w\-]{11}).*[^\s<]/gi,
		'movie_url': 'http://www.youtube.com/v/$2&hl=cs&fs=1&rel=0'
	},
	'dailymotion': {
		'regexp': /http:\/\/www\.dailymotion\.com\/.*video\/([a-z0-9]+).*[^\s<]/gi,
		'movie_url': 'http://www.dailymotion.com/swf/$1'
	},
	'myspace': {
		'regexp': /http:\/\/vids.myspace.com\/index.cfm\?.*videoid=([0-9]+).*[^\s<]/gi,
		'movie_url': 'http://mediaservices.myspace.com/services/media/embed.aspx/m=$1,t=1,mt=video'
	},
	'vimeo': {
		'regexp': /http:\/\/(www\.|\w{2}\.|)vimeo.com\/([0-9]+).*[^\s<]/gi,
		'movie_url': 'http://vimeo.com/moogaloop.swf?clip_id=$2&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1'
	}
};

(function($) {
	$.fn.extend({
		clickableURL: function() {
			var regexp = /((ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;  
			this.each(function() {  
				$(this).html(  
					$(this).html().replace(regexp,'<a href="$1">$1</a>')
				);  
			});  
			return $(this);
		}
	});
	$.fn.extend({
		embedVideo: function() {
			var obj = this;
			$.each(
				codecs,
				function(i, val){
					obj.each(function() {  
						var regexp = val.regexp;
						var html = embeded_code.replace(/\{\{ url \}\}/gi, val.movie_url);
						$(this).html(
							$(this).html().replace(regexp, html)
						); 
					});
				}
			);  
			return $(this);
		}
	});
})(jQuery);