
document.observe("dom:loaded",
	function()
	{
		function randomString(string_length) {
			var chars = "0123456789abcdefghiklmnopqrstuvwxyz";
			var randomstring = '';

			for (var i=0; i<string_length; i++) {
				var rnum = Math.floor(Math.random() * chars.length);
				randomstring += chars.substring(rnum,rnum+1);
			}

			return randomstring;
		}
		
		var wmv_embed = '';
		if (Prototype.Browser.IE)
		{
			wmv_embed += '<object type="video/x-ms-wmv" data="#src#" width="#width#" height="#height#">';
			wmv_embed += '  <param name="src" value="#src#" />';
			wmv_embed += '  <param name="autostart" value="false" />';
			wmv_embed += '  <param name="controller" value="true" />';
			wmv_embed += '</object>';
		}
		else
		{
			wmv_embed += '<object id="MediaPlayer" width="#width#" height="#height#" classid="CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95" standby="Loading Windows Media Player components..." type="application/x-oleobject" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112">';
			wmv_embed += '<param name="filename" value="#src#">';
			wmv_embed += '<param name="Showcontrols" value="True">';
			wmv_embed += '<param name="autoStart" value="False">';
			wmv_embed += '<embed type="application/x-mplayer2" src="#src#" name="MediaPlayer" width="#width#" height="#height#"></embed>';
			wmv_embed += '</object>';	
		}
		
		var array = $$('#page_content embed, .leftHandBoxOut embed, .rightHandBoxOut embed');
		array.each(
			function(embed)
			{
				if (embed.actualType == 'application/x-shockwave-flash' || (embed.outerHTML && embed.outerHTML.indexOf('application/x-shockwave-flash') > -1))
				{
					var container = document.createElement('div');

					container.id = "flash_" + randomString(5);
					new Insertion.Before(embed, container);
					embed.style.display = 'none';

					swfobject.embedSWF(
						embed.src,
						container.id,
						embed.width,
						embed.height,
						"9.0.0",
						embed.pluginspage,
						null,
						{
							loop: embed.loop,
							menu: embed.menu,
							quality: embed.quality,
							salign: embed.salign,
							wmode: 'transparent'
						}
					);
				}
				else if (embed.actualType == 'application/x-mplayer2' || (embed.outerHTML && embed.outerHTML.indexOf('application/x-mplayer2') > -1))
				{
					var html = wmv_embed;
					html = html.replace(/#src#/g, embed.src);
					html = html.replace(/#width#/g, embed.style.width.replace('px',''));
					html = html.replace(/#height#/g, embed.style.height.replace('px',''));
					var container = document.createElement('div');
					container.innerHTML = html;
					
					container.id = "flash_" + randomString(5);
					for (var i = 0; i < embed.attributes.length; i++)
					{
						if (embed.attributes[i].name == 'style')
						{
							container.setAttribute('style', embed.attributes[i].nodeValue);
							break;
						}
					}
					
					new Insertion.Before(embed, container);
					embed.style.display = 'none';
				
				}
			}
		);
	}
)
