jQuery(document).ready(function() {
	jQuery('.vid_strip_field').vid_strip();
});




(function($) {
	
	$.fn.vid_strip = function (field) {
		return this.each(function() {
			
			// Bind to the check function
			//$(this).change(function() { vid_strip(this); });
			$(this).blur(function() { vid_strip(this); });
			
			// Initial check
			vid_strip(this);
		});
	};

	vid_strip = function(field) {
		var $this = $(field);
		var source = $this.val();
		var output = "";
		if (source.indexOf('youtube') > 0 )
		{
			var output = source.match(/youtube\.com\/v\/([\w\-]+)/);
			
		}
		if (source.indexOf('vimeo.com') > 0 )
		{
			var output = source.match(/vimeo\.com\/moogaloop.swf\?clip_id=([\w\-]+)/);
			
		}
		if (source.indexOf('veoh.com') > 0 )
		{
			var output = source.match(/watch\/([\w\-]+)/);
			
		}
		if (source.indexOf('brightcove.com') > 0 )
		{
			var output = source.match(/videoId=([\w\-]+)/);
			
		}
		$this.val(output[1]);
		

	};

})(jQuery);