/* 

   proTube v0.1 - alfa (10.03.2010)
   plugin for jQuery
   (c) http://developing.name/, http://otpro.ru/
   
   
*/

$(document).bind("ready", function() {
 
      $(".tube").tube();
 
});

(function($) {

	$.fn.tube = function() {
		
		
		function youtube(str, id)
		{
			return '<object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/' + id + '"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><param name="wmode" value="opaque"></param><embed src="http://www.youtube.com/v/' + id + '" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385" wmode="opaque"></embed></object>'
		}
		
		$(this).each( function(b,c,a) {
		
			var html = $(this).html();
			
			var re = new RegExp("http:\/\/www.youtube.com\/watch[?]+v=([-_0-9a-zA-Z]+)[^ <\r\n\t]*", "mig");
		
			var htmlnew = html.replace(re, youtube);
			
			if (htmlnew != html)
			{
				$(this).html(htmlnew);
			}
			
		});
				
	}
					
})(jQuery);



