/**
 * WickedJS Media Parser
 * 
 * Parses special YouTube and SWF tags, to allow easy addition
 * of YouTube and Flash/Flex files in pages via a CMS and
 * still have the pages validate.
 * 
 * Currently this parses P tags that use the following formats:
 * 
 * For YouTube:  <p class="youtube">videoId:width:height:autoplay</p>
 *     example:  <p class="youtube">4pXfHLUlZf4:480:295:0</p>
 * 
 * For a SWF: <p class="swf">/path/to/file.swf:width:height</p>
 *   example: <p class="swf">/swfs/MyAnimation.swf:600:400</p>
 * 
 * @author Gordon Clemmons
 */
Wicked.parseMediaTags = function()
{
	var tags	= document.getElementsByTagName('p');
	for ( var t = 0; t < tags.length; t++ )
	{
		var tag	= tags[t];
		if ( Wicked.hasClassName( tag, 'swf' ) )
		{
			var args	= tag.innerHTML.split(':');
			var path	= args[0];
			var width	= args[1];
			var height	= args[2];

			var html	=	'<div><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" ' +
							'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" ' +
							'width="' + width + '" height="' + height + '" id="YoutubeVideo">' + "\n" +
							'<param name="allowScriptAccess" value="sameDomain" /> ' +
							'<param name="wmode" value="transparent" />' +
							'<param name="allowFullScreen" value="false" /> ' +
							'<param name="movie" value="' + path + '" /> ' +
							'<param name="quality" value="high" /> ' +
							'<param name="bgcolor" value="#313339" /> ' + "\n" +
							'<embed src="' + path + '" quality="high" wmode="transparent" bgcolor="#ffffff" width="' + width + '" height="' + height + '" name="Flash File" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /> ' +
							'</object></div>';
							
			var div			= document.createElement('div');
			div.innerHTML	= html;
			tag.innerHTML = '';
			tag.style.display	= 'block';
			tag.appendChild(div);
		} else if ( Wicked.hasClassName( tag, 'youtube' ) ) {
			var args	= tag.innerHTML.split(':');
			var id		= args[0];
			var width	= args[1];
			var height	= args[2];
			var auto	= args[3];
			if ( !auto )
				auto = '0';

			var html	= Wicked.getYouTubeVideo( id, width, height, auto );
			var div			= document.createElement('div');
			div.innerHTML	= html;
			tag.innerHTML = '';
			tag.style.display	= 'block';
			tag.appendChild(div);
		}
	}
};

// register the parser to be called on init
Wicked.registerInit( Wicked.parseMediaTags );

