/**
 * Magically convert links to youtube videos to embedded videos
 *
 * @requires jQuery
 * @author Nathan White
 */

$(document).ready(function()
{
	$("a[href*='://www.youtube.com']").each( function()
	{
		var html;
		var vid_id = getYouTubeID($(this).attr('href'));
		if (vid_id) // lets build xhtml embedding markup at a standard youtube size 425 x 344
		{
			html = '<object type="application/x-shockwave-flash" data="http://www.youtube.com/v/'+vid_id+'"'; 
			html += ' width="425" height="344">';
			html += ' <param name="movie" value="http://www.youtube.com/v/'+vid_id+'" />';
			html += ' <param name="wmode" value="transparent" /></object>';
			$(this).html(html);
		}
	});
	
	function getYouTubeID(url)
	{
		var id = url.match("[\\?&]v=([^&#]*)");
		return (id[1]) ? id[1] : false;
	};
});
