// ==UserScript==
// @name YouTube Embedinator
// @namespace http://www.lmnopc.com/
// @description Replaces links to popular video sites with embedded videos
// @include http://shacknews.com/laryn.x?story=*
// @include http://*.shacknews.com/laryn.x?story=*
// @include http://shacknews.com/laryn.x?id=*
// @include http://*.shacknews.com/laryn.x?id=*
// @include http://*.shacknews.com/frame_laryn.x?*
// @include http://shacknews.com/frame_laryn.x?*
// @include http://shacknews.com/ja.zz?comments=*
// @include http://*.shacknews.com/ja.zz?comments=*
// @include http://shacknews.com/ja.zz?id=*
// @include http://*.shacknews.com/ja.zz?id=*
// @include http://stoofoo.net/chatty.x*
// @include http://*.stoofoo.net/chatty.x*
// @include http://stoofoo.net/handler.x?*
// @include http://*.stoofoo.net/handler.x?*
// @include http://*.lmnopc.com/greasemonkey/shacklol/*
// @include http://lmnopc.com/greasemonkey/shacklol/*
// @include http://*.thomwetzel.com/greasemonkey/shacklol/*
// @include http://thomwetzel.com/greasemonkey/shacklol/*
// @exclude http://*.youtube.com/*
// @exclude http://youtube.com/*
// @exclude http://video.google.com/*
// @exclude http://*.collegehumor.com/*
// @exclude http://collegehumor.com/*
// @exclude http://break.com/*
// @exclude http://*.break.com/*
// @exclude http://ifilm.com/*
// @exclude http://*.ifilm.com/*
// @exclude http://metacafe.com/*
// @exclude http://*.metacafe.com/*
// @exclude http://revver.com/*
// @exclude http://*.revver.com/*
// @exclude http://vids.myspace.com/*
// @exclude http://*.myspace.com/*
// @exclude http://liveleak.com/*
// @exclude http://*.liveleak.com/*
// @exclude http://clipstr.com/*
// @exclude http://*.clipstr.com/*
// @exclude http://*.superdeluxe.com/*
// @exclude http://superdeluxe.com/*
// @exclude http://*.gametrailers.com/*
// @exclude http://gametrailers.com/*
// @exclude http://*.gamespot.com/*
// @exclude http://gamespot.com/*
// @exclude http://*.gamevideos.com/*
// @exclude http://gamevideos.com/*
// @exclude http://*.adultswim.com/*
// @exclude http://adultswim.com/*
// @exclude http://video.msn.com/*
// @exclude http://myspacetv.com/*
// @exclude http://stage6.com/*
// @exclude http://www.stage6.com/*
// @exclude http://funnyordie.com/*
// @exclude http://www.funnyordie.com/*
// @exclude http://veoh.com/*
// @exclude http://www.veoh.com/*
// @exclude https://tv.rockstargames.com/*

// ==/UserScript==
/*
	YouTube Embedinator
	(C) 2006-2009 Thom Wetzel / www.lmnopc.com
				
	I wrote this thing to make it compatible with Shacknews, but I'm not sure why it wouldn't
	work on other sites ... except for the dThread stuff.  haha
	
	2006-11-02 Initial releae
	2006-11-05 Google Video support added
	2006-11-05 Replaced all the innnerHTML mess with real code
	2006-11-05 CollegeHumor support added
	
	2006-11-06 00:34
		* Fixed Google Video after gooning it up during the College Humor update
		* Changed insert method to insert video before anchor, and shrink down anchor text instead of killing it
		
	2006-11-06 02:14
		* Subthread support
		
	2006-11-09 
		* Break.com support started
		
	2006-11-10
		* iFilm support added
		* MetaCafe support added
		
	2006-11-12
		* iFilm bug fixed
		
	2006-11-16
		* Revver support added
		* Metacafe bug fixed (I really need to start making posts to test this crap... haha)
		* I'm not shrinking the links any more ...
		
	2006-12-02
		* MySpace support added
		
	2007-01-21
		* LiveLeak.com support added
		
	2007-01-21 b
		* clipstr.com support added 

	2007-01-31
		* Changed list of supported sites to include Shacklol
		
	2007-02-16
		* On 1/31 I somehow added Shacklol support but made the changes to an
			old version of the script and uploaded it, losing all the changes since
			2006-11-16.
			
	2007-02-23
		* YouTube additional querystring variables fix
		
	2007-02-26
		* SuperDeluxe.com support added
		
	2007-06-13
		* Updated to include improved support for the Shacknews redesign
		
	20070-06-16
		* Updated Shack2007 support to correct the issues found in Shack-lol
		* Tried adding GameTrailers.com but it doesn't work.  Not sure why.  
		
	2007-07-13
		* Got gametrailers.com working
	
	2007-07-14
		* Gamespot.com added
		
	2007-07-24
		* Gamevideos.com added
		
	2007-11-28
		* AdultSwim.com added 
		* Added createParam() function to streamline things a bit.  
			I'm a little confused why my attempts to add a 'addParam(name,value)' 
			method to the Object and/or Element via prototype didn't work but 
			I can tackle that a different time. 
		* Fixed a problem with CollegeHumor.com videos 
	
	2007-12-12
		* video.msn.com added
		
	2008-01-31
		* myspacetv.com added
		* Fixed case-issue with vids.myspace.com (VideoId vs videoid ... FIGHT!)
		
	2008-02-01
		* Added support for ca.youtube.com
		
	2008-02-09
		* Updated to fix problem with isArray function causing new version of Firefox to crash
		
	2008-02-16
		* Incorporated steelsamurai's observation about document not always being the correct document ... 
		* Added Stage6 support
		* Fixed Refresh Thread error 
		
	2008-02-18
		* Fixed Youtube so that any country should work now instead of just www. and ca. 
		* Commented out ShackPics by default.  Search for bImageShackpics and delete the beginning of that line to enable it.  
		
	2008-02-18
		* Funnyordie.com added 
		
	2008-02-19
		* veoh.com added 
		
	2008-02-22
		* Re-fixed yte_replace_whole_element_from_iframe so it hopefully won't hang anymore, or cause videos from being re-embedded
		
	2008-02-24
		* stoofoo support
		
	2008-08-12
		* Youtube: Adds &fmt=18 to links that don't have it
		
	2008-11-14
		* Youtube: Added fmt=18 hack to embeded videos 
		
	2008-11-25
		* Youtube: Wide video 
		
	2009-01-03
		* tv.rockstar.com added
		
*/
(function() {

	// standard functions
	function getTime() { benchmarkTimer = new Date(); return benchmarkTimer.getTime(); }
	
	
	function TW_log(str)
	{
		if (GM_log)
		{
			GM_log(str);
		}
	}

	// grab start time of script
	var benchmarkTimer = null;
	var scriptStartTime = getTime();

	// returns first element matching className
	function getElementByClassName(oElm, strTagName, strClassName)
	{
		var arrElements = oElm.getElementsByTagName(strTagName);
		var oElement;
		for(var i=0; i < arrElements.length; i++)
		{
			oElement = arrElements[i];
			if (oElement.className.indexOf(strClassName) == 0)
			{
				return oElement;
			}
		}
	}	

	// returns array of all items matching className
	function getElementsByClassName(className, tag, elm)
	{
		var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
		var tag = tag || "*";
		var elm = elm || document;
		var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
		var returnElements = [];
		var current;
		var length = elements.length;
		for(var i=0; i<length; i++){
			current = elements[i];
			if(testClass.test(current.className)){
				returnElements.push(current);
			}
		}
		return returnElements;
	}
	
	// 
	function isArray(obj) 
	{
	   // return (obj.constructor.toString().indexOf("Array") != -1);  // crash
	   return obj.constructor == Array;
	}
	
	function createParam(doc, name, value)
	{
			var p = doc.createElement('param');
			p.setAttribute('name', name);
			p.setAttribute('value', value);
			return p; 
	}

//
thomwEmbedVideos = function(a)
{
	// thomwEmbedVideos can accept an array to make processing faster.  
	// if tgt isn't an array, it'll find the anchors that are children of whatever DOM object tgt is 

	if (!isArray(a))
	{
		a = a.getElementsByTagName('a');
	}
	
	for (i = 0; i < a.length; i++)
	{
		var doc = a[i].parentNode.ownerDocument;

		// look at href and see if it points at a youtube video
		var href = a[i].getAttribute('href');
		if (!href) { continue; }
		
		var bYouTube = (href.indexOf('youtube.com/watch?v=') != -1);
		var bGoogVid = (href.indexOf('http://video.google.com/videoplay?docid=') == 0);
		var bCollegeHumorVid = ((href.indexOf('http://collegehumor.com/video:') == 0) || (href.indexOf('http://www.collegehumor.com/video:') == 0));
		var bIFilm = ((href.indexOf('http://ifilm.com/video/') == 0) || (href.indexOf('http://www.ifilm.com/video/') == 0));
		var bMetacafe = ((href.indexOf('http://metacafe.com/watch/') == 0) || (href.indexOf('http://www.metacafe.com/watch/') == 0));
		var bRevverVid = (href.indexOf('http://one.revver.com/watch/') == 0);
		var bMySpaceVids = ((href.toLowerCase().indexOf('http://vids.myspace.com/index.cfm?fuseaction=vids.individual&videoid=') == 0) || (href.indexOf('http://myspacetv.com/') == 0) || (href.indexOf('http://www.myspacetv.com/') == 0))
		var bLiveLeak = ((href.indexOf('http://www.liveleak.com/view?i=') == 0) || (href.indexOf('http://liveleak.com/view?i=') == 0));
		var bClipstr = ((href.indexOf('http://www.clipstr.com/videos/') == 0) || (href.indexOf('http://clipstr.com/videos/') == 0));
		var bSuperDeluxe = ((href.indexOf('http://www.superdeluxe.com/sd/contentDetail.do?id=') == 0) || (href.indexOf('http://superdeluxe.com/sd/contentDetail.do?id=') == 0));
		var bGameTrailers = ((href.indexOf('http://www.gametrailers.com/player/') == 0) || (href.indexOf('http://gametrailers.com/player/') == 0));
		var bGamespot = ((href.indexOf('http://www.gamespot.com/video/') == 0) || (href.indexOf('http://gamespot.com/video/') == 0));
		var bGamevideos = ((href.indexOf('http://www.gamevideos.com/video/id/') == 0) || (href.indexOf('http://gamevideos.com/video/id/') == 0));
		var bAdultSwim = ((href.indexOf('http://www.adultswim.com/video/?episodeID=') == 0) || (href.indexOf('http://adultswim.com/video/?episodeID=') == 0));
		var bVideoMsn = (href.indexOf('http://video.msn.com/video.aspx?') == 0);
		// var bBreakVid = ((href.indexOf('http://break.com/index/') == 0) || (href.indexOf('http://www.break.com/index/') == 0));
		bImageShackpics = false; // var bImageShackpics =  ((href.indexOf('http://shackpics.com/') == 0) || (href.indexOf('http://www.shackpics.com/') == 0));
		var bStage6 =  ((href.indexOf('http://stage6.com/') == 0) || (href.indexOf('http://www.stage6.com/') == 0));
		var bFunnyOrDie =  ((href.indexOf('http://funnyordie.com/videos/') == 0) || (href.indexOf('http://www.funnyordie.com/videos/') == 0));
		var bVeoh =  ((href.indexOf('http://veoh.com/videos/') == 0) || (href.indexOf('http://www.veoh.com/videos/') == 0));
		var bRockstar = (href.indexOf('https://tv.rockstargames.com/videos/view/id/') == 0);
		
		// if a supported video link isn't found, skip this link
		if (bVeoh + bFunnyOrDie + bStage6 + bImageShackpics + bYouTube + bGoogVid + bCollegeHumorVid + bIFilm + bMetacafe + bRevverVid + bMySpaceVids + bLiveLeak + bClipstr + bSuperDeluxe + bGameTrailers + bGamespot + bGamevideos + bAdultSwim + bVideoMsn + bRockstar == 0) { continue; }
		
		if (bYouTube)
		{		
			// YouTube link:  http://www.youtube.com/watch?v=Rooan3ZnDko
			// YouTube embedded: <object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/Rooan3ZnDko"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/Rooan3ZnDko" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>
			
			// Add &fmt=18 to the link
			if (href.indexOf('fmt=18') == -1)
			{
				a[i].setAttribute('href', href + '&fmt=18');
			}
			
			// Get the domain 
			var domain = String(href);
			if (domain.substr(0, 7) == 'http://')
			{
				domain = domain.substr(7);
			}
			if (domain.indexOf('/') != -1)
			{
				domain = domain.substring(0, domain.indexOf('/'));
			}

			// find v= and grab the id
			var pos = href.indexOf('v=');
			if (pos == -1) { continue; }
			
			// get the video's id	
			var videoId = href.substr(pos + 2);
			videoId = videoId.split('&');
			videoId = videoId[0];
			
			// create a container for the video 
			var el = doc.createElement('object');
			el.style.display = 'block';
			el.setAttribute('width', '640'); // '425');
			el.setAttribute('height', '385'); // '350');

			el.appendChild(createParam(doc, 'movie', 'http://' + domain + '/v/' + videoId + '&hl=en&fs=1&ap=%2526fmt%3D18'));
			el.appendChild(createParam(doc, 'wmode', 'transparent'));
			
			// <embed src="http://www.youtube.com/v/' + videoId + '" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed>
			var em = doc.createElement('embed');
			em.setAttribute('src', 'http://' + domain + '/v/' + videoId + '&hl=en&fs=1&ap=%2526fmt%3D18');
			em.setAttribute('type', 'application/x-shockwave-flash');
			em.setAttribute('wmode', 'transparent');
			em.setAttribute('width', '640'); // '425');
			em.setAttribute('height', '385'); // '350');
			
			el.appendChild(em);
		}
		else if (bGoogVid)
		{
			// Google link: http://video.google.com/videoplay?docid=6067987480536636701&q=funny+cat
			// Google embedded: <embed style="width:400px; height:326px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docId=6067987480536636701&hl=en" flashvars=""> </embed>
			
			// find v= and grab the id
			var pos = href.indexOf('docid=');
			if (pos == -1) { continue; }
			
			// get the video's id	
			var videoId = href.substr(pos + 6);
			videoId = videoId.split('&');
			videoId = videoId[0];
			
			// create a container for the video 
			var el = doc.createElement('embed');
			el.setAttribute('style', 'display: block; width:400px; height: 326px');
			el.setAttribute('id', 'VideoPlayback');
			el.setAttribute('type', 'application/x-shockwave-flash');
			el.setAttribute('src', 'http://video.google.com/googleplayer.swf?docId=' + videoId + '&hl=en');
			el.setAttribute('flashvars', '');
		}
		else if (bVeoh)
		{
			/*
			http://www.veoh.com/videos/v7588616PA5xgQD
			
			<embed 
				src="http://www.veoh.com/videodetails2.swf?permalinkId=v7588616PA5xgQD&id=anonymous&player=videodetailsembedded&videoAutoPlay=0" 
				allowFullScreen="true" 
				width="540" 
				height="438" 
				bgcolor="#000000" 
				type="application/x-shockwave-flash" 
				pluginspage="http://www.macromedia.com/go/getflashplayer">
			</embed>				
			*/
			
			// get video id 
			var pos = href.indexOf('/videos/');
			if (pos == -1) { continue; }
			var videoId = href.substr(pos + 8); 
			videoId = videoId.split('/');
			videoId = videoId[0];

			var el = doc.createElement('embed');
			el.setAttribute('style', 'display: block; margin: 10px 0;');
			el.setAttribute('src', 'http://www.veoh.com/videodetails2.swf?permalinkId=' + videoId + '&id=anonymous&player=videodetailsembedded&videoAutoPlay=0');
			el.setAttribute('allowFullScreen', 'true');
			el.setAttribute('width', '540');
			el.setAttribute('height', '438');
			el.setAttribute('bgcolor', '#000000');
			el.setAttribute('type', 'application/x-shockwave-flash');
			el.setAttribute('pluginspage', 'http://www.macromedia.com/go/getflashplayer');
		}
		
		else if (bFunnyOrDie)
		{
			/*
			http://www.funnyordie.com/videos/44234ba1ec
			<object width="464" height="388" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000">
				<param name="movie" value="http://www2.funnyordie.com/public/flash/fodplayer.swf?1202361338" />
				<param name="flashvars" value="key=44234ba1ec" />
				<param name="allowfullscreen" value="true" />
				<embed 
					width="464" 
					height="388" 
					flashvars="key=44234ba1ec" 
					allowfullscreen="true" 
					quality="high" 
					src="http://www2.funnyordie.com/public/flash/fodplayer.swf?1202361338" 
					type="application/x-shockwave-flash">
				</embed>
			</object>
			*/
			
			// get video id 
			var pos = href.indexOf('/videos/');
			if (pos == -1) { continue; }
			var videoId = href.substr(pos + 8); 
			videoId = videoId.split('/');
			videoId = videoId[0];
			
			// object
			var el = doc.createElement('object');
			el.setAttribute('style', 'display: block;');
			el.setAttribute('height','388');
			el.setAttribute('width','464');
			el.setAttribute('classid','clsid:d27cdb6e-ae6d-11cf-96b8-444553540000');

			el.appendChild(createParam(doc, 'movie', 'http://www2.funnyordie.com/public/flash/fodplayer.swf?1202361338'));
			el.appendChild(createParam(doc, 'flashvars', 'key=' + videoId));
			el.appendChild(createParam(doc, 'allowfullscreen', 'true'));
			
			var em = doc.createElement('embed');
			em.setAttribute('width', "464");
			em.setAttribute('height', "388");
			em.setAttribute('flashvars', 'key=' + videoId);
			em.setAttribute('allowfullscreen', "true");
			em.setAttribute('quality', 'high');
			em.setAttribute('src', 'http://www2.funnyordie.com/public/flash/fodplayer.swf?1202361338');
			em.setAttribute('type', 'application/x-shockwave-flash');
			
			el.appendChild(em);
		}
		else if (bStage6)
		{	
				/*
				// http://www.stage6.com/Hamster-Hell/video/1479914/Hamster-stuck-in-Video-Game
				// 
				<object codebase="http://go.divx.com/plugin/DivXBrowserPlugin.cab" height="360" width="480" classid="clsid:67DABFBF-D0AB-41fa-9C46-CC0F21721616">
					<param name="autoplay" value="false">
					<param name="src" value="http://video.stage6.com/1479914/.divx" />
					<param name="custommode" value="Stage6" />
					<param name="showpostplaybackad" value="false" />
					<embed type="video/divx" src="http://video.stage6.com/1479914/.divx" pluginspage="http://go.divx.com/plugin/download/" showpostplaybackad="false" custommode="Stage6" autoplay="false" height="360" width="480" />
				</object>
				*/

			// get video id 
			var pos = href.indexOf('/video/');
			if (pos == -1) { continue; }
			var videoId = href.substr(pos + 7); 
			videoId = videoId.split('/');
			videoId = videoId[0];
			
			// object
			var el = doc.createElement('object');
			el.setAttribute('style', 'display: block;');
			el.setAttribute('codebase', 'http://go.divx.com/plugin/DivXBrowserPlugin.cab');
			el.setAttribute('height','360');
			el.setAttribute('width','480');
			el.setAttribute('classid','clsid:67DABFBF-D0AB-41fa-9C46-CC0F21721616');

			el.appendChild(createParam(doc, 'autoplay', 'false'));
			el.appendChild(createParam(doc, 'src', 'http://video.stage6.com/' + videoId + '/.divx'));
			el.appendChild(createParam(doc, 'custommode', 'Stage6'));
			el.appendChild(createParam(doc, 'showpostplaybackad', 'false'));
			
			var em = doc.createElement('embed');
			em.setAttribute('type', 'video/divx');
			em.setAttribute('src', "http://video.stage6.com/" + videoId + "/.divx");
			em.setAttribute('pluginspage', "http://go.divx.com/plugin/download/");
			em.setAttribute('showpostplaybackad', "false");
			em.setAttribute('custommode' , "Stage6");
			em.setAttribute('autoplay', "false");
			em.setAttribute('height', "360");
			em.setAttribute('width', "480");
			
			el.appendChild(em);
			
		}
    else if (bImageShackpics) 
		{
			// BUGFIX: extra code here works around errors 
			// elsewhere, should be migrated over to the
			// rest of the function

			// find file= and grab the id
			var prefix = 'file=';
			var pos = href.indexOf(prefix);
			if (pos == -1) 
			{ 
				// ok not that, so check for direct linkage
				prefix = 'files/' ;
				var pos = href.indexOf(prefix);
				if (pos == -1) { continue; } 
			}		
			
			// get the image's id	
			var imageold = href.substr(pos + prefix.length);
			imageold = imageold.split('&');
			imageold = imageold[0];
			
			// image type to stick into the embed
			var type = imageold.split('.');
			if (type.length < 2) { continue ; }
			type = type[1];

/*
			// set up to add our nodes properly
			var parentNode = a[i].parentNode;
			
			// the ownerDocument is not necessarily "document", 
			// so we have to get it explicitly... this WILL
			// cause an exception to be thrown
			var doc = parentNode.ownerDocument;

			// using _el and adding manually because the rest 
			// of the code be broke and will throw exceptions
			var _el = doc.createElement('embed');
		
			// preview is 426 wide, will scale auto
			_el.setAttribute('style', 'display: block; width: 426px;');
			_el.setAttribute('type', 'image/' + type);
  			_el.setAttribute('src', 'http://shackpics.com/files/' + imageold);

			try {
				ret = parentNode.insertBefore(_el, a[i]);
		      } catch (e) {
				alert("ERROR: " + e.name + " : " + e.message);
			}
*/
			el = doc.createElement('embed');
			el.setAttribute('style', 'display: block; width: 426px;');
			el.setAttribute('type', 'image/' + type);
  		el.setAttribute('src', 'http://shackpics.com/files/' + imageold);
    }
		else if (bCollegeHumorVid)
		{
			// http://www.collegehumor.com/video:1710927
			// <embed src="http://www.collegehumor.com/moogaloop/moogaloop.swf?clip_id=1710927" quality="best" width="400" height="300" type="application/x-shockwave-flash"></embed>

			// find video: and grab the id
			var pos = href.indexOf('video:');
			if (pos == -1) { continue; }
			
			// get the video's id	
			var videoId = href.substr(pos + 6);
			videoId = videoId.split('/');
			videoId = videoId[0];
			
			// create a container for the video 
			var el = doc.createElement('embed');
			el.setAttribute('style', 'display: block;');
			el.setAttribute('width', '400');
			el.setAttribute('height', '300');
			el.setAttribute('quality', 'best');
			el.setAttribute('type', 'application/x-shockwave-flash');
			el.setAttribute('src', 'http://www.collegehumor.com/moogaloop/moogaloop.swf?clip_id=' + videoId);
		}
		else if (bIFilm)
		{
			// http://www.ifilm.com/video/2795826
			// <embed width="448" height="365" src="http://www.ifilm.com/efp" quality="high" bgcolor="000000" name="efp" align="middle" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="flvbaseclip=2795826&"> </embed>
		
			// find video: and grab the id
			var pos = href.indexOf('/video/');
			if (pos == -1) { continue; }
			pos += 7;
			
			// get the video's id	
			var videoId = href.substr(pos);
			videoId = videoId.split('?');
			videoId = videoId[0];
			
			// create a container for the video 
			var el = doc.createElement('embed');
			el.setAttribute('style', 'display: block;');
			el.setAttribute('width', '448');
			el.setAttribute('height', '365');
			el.setAttribute('src', 'http://www.ifilm.com/efp');
			el.setAttribute('quality', 'high');
			el.setAttribute('bgcolor', '000000');
			el.setAttribute('name', 'efp');
			el.setAttribute('align', 'middle');
			el.setAttribute('type', 'application/x-shockwave-flash');
			el.setAttribute('pluginspage', 'http://www.macromedia.com/go/getflashplayer');
			el.setAttribute('flashvars', 'flvbaseclip=' + videoId + '&');
		}
		else if (bMetacafe)
		{
			// http://www.metacafe.com/watch/262984/security_surf/
			// <embed src="http://www.metacafe.com/fplayer/262984/security_surf.swf" width="400" height="300" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed><br><font size = 1><a href="http://www.metacafe.com/watch/262984/security_surf/">Security Surf - video powered by Metacafe</a></font>

			// find the id
			var pos = href.indexOf('watch/');
			if (pos == -1) { continue; }
			
			// get the video's id	
			var url = href.substr(pos + 6);
			url = url.split('/');
			var title = url[1];
			var videoId = url[0];
			
			// create a container for the video
			var el = doc.createElement('embed');
			el.setAttribute('style', 'display: block; margin: 10px 0;');
			el.setAttribute('width', '400');
			el.setAttribute('height', '300');
			el.setAttribute('wmode', 'transparent');
			el.setAttribute('pluginspage', 'http://www.macromedia.com/go/getflashplayer');
			el.setAttribute('type', 'application/x-shockwave-flash');
			el.setAttribute('src', 'http://www.metacafe.com/fplayer/' + videoId + '/' + title + '.swf');
		}
		else if (bRevverVid)
		{
			/*
			http://one.revver.com/watch/95332/format/flv/affiliate/5642
			<embed type="application/x-shockwave-flash" src="http://flash.revver.com/player/1.0/player.swf" pluginspage="http://www.macromedia.com/go/getflashplayer" scale="noScale" salign="TL" bgcolor="#ffffff" flashvars="width=480&height=392&mediaId=95332&affiliateId=0&javascriptContext=true&skinURL=http://flash.revver.com/player/1.0/skins/Default_Raster.swf&skinImgURL=http://flash.revver.com/player/1.0/skins/night_skin.png&actionBarSkinURL=http://flash.revver.com/player/1.0/skins/DefaultNavBarSkin.swf&resizeVideo=True" wmode="transparent" height="392" width="480"></embed>
			*/

			// find the id
			var pos = href.indexOf('watch/');
			if (pos == -1) { continue; }
			pos += 6; 
			
			// get the video's id	
			var url = href.substr(pos);
			url = url.split('/');
			var videoId = url[0];
			
			// create a container for the video
			var el = doc.createElement('embed');
			el.setAttribute('style', 'display: block;');
			el.setAttribute('type', 'application/x-shockwave-flash');
			el.setAttribute('src', 'http://flash.revver.com/player/1.0/player.swf');
			el.setAttribute('pluginspage', 'http://www.macromedia.com/go/getflashplayer');
			el.setAttribute('scale', 'noScale');
			el.setAttribute('salign', 'TL');
			el.setAttribute('bgcolor', '#ffffff');
			el.setAttribute('flashvars', 'width=480&height=392&mediaId=' + videoId + '&affiliateId=0&javascriptContext=true&skinURL=http://flash.revver.com/player/1.0/skins/Default_Raster.swf&skinImgURL=http://flash.revver.com/player/1.0/skins/night_skin.png&actionBarSkinURL=http://flash.revver.com/player/1.0/skins/DefaultNavBarSkin.swf&resizeVideo=True');
			el.setAttribute('wmode', 'transparent');
			el.setAttribute('height', '392');
			el.setAttribute('width', '480');
		}
		else if (bLiveLeak)
		{		
			// http://www.liveleak.com/view?i=501ab_4407
			/*
			<object type="application/x-shockwave-flash" width="450" height="370" wmode="transparent" data="http://www.liveleak.com/player.swf?autostart=false&token=501ab_4407">
				<param name="movie" value="http://www.liveleak.com/player.swf?autostart=false&token=501ab_4407">
				<param name="wmode" value="transparent">
				<param name="quality" value="high">
			</object>
			*/

			// find i= and grab the id
			var pos = href.indexOf('i=');
			if (pos == -1) { continue; }
			
			// get the video's id	
			var videoId = href.substr(pos + 2);
			videoId = videoId.split('&');
			videoId = videoId[0];
			
			// create a container for the video 
			var el = doc.createElement('object');
			el.style.display = 'block';
			el.setAttribute('type', 'application/x-shockwave-flash');
			el.setAttribute('width', '450');
			el.setAttribute('height', '370');
			el.setAttribute('wmode', 'transparent'); 
			el.setAttribute('data', 'http://www.liveleak.com/e/' + videoId);

			el.appendChild(createParam(doc, 'movie', 'http://www.liveleak.com/e/' + videoId));
			el.appendChild(createParam(doc, 'wmode', 'transparent'));
			el.appendChild(createParam(doc, 'quality','high'));

		}
		else if (bClipstr)
		{
			// link: http://www.clipstr.com/videos/PaintballToTheEye/
			// embed: <object type="application/x-shockwave-flash" data="http://www.clipstr.com/player/embed.swf" width="400" height="300" wmode="transparent" flashvars="file=PaintballToTheEye">	<param name="movie" value="http://www.clipstr.com/player/embed.swf" /> <param name="wmode" value="transparent" /><param name="flashvars" value="file=PaintballToTheEye" /></object>
			
			// find videoId
			var pos = href.indexOf('/videos/');
			if (pos == -1) { continue; }
			
			// get the video's id	
			var videoId = href.substr(pos + 8);
			videoId = videoId.split('/')[0];
			
			// create a container for the video 
			var el = doc.createElement('object');
			el.setAttribute('style', 'display: block;');
			el.setAttribute('type', 'application/x-shockwave-flash');
			el.setAttribute('data' , 'http://www.clipstr.com/player/embed.swf');
			el.setAttribute('width', '400');
			el.setAttribute('height', '300');
			el.setAttribute('wmode', 'transparent');
			el.setAttribute('flashvars' , 'file=' + videoId);
			
			el.appendChild(createParam(doc, 'movie', 'http://www.clipstr.com/player/embed.swf'));
			el.appendChild(createParam(doc, 'wmode', 'transparent'));
			el.appendChild(createParam(doc, 'flashvars', 'file=' + videoId + '&showdigits=true&showfsbutton=true'));
		}		
		else if (bMySpaceVids)
		{
			// http://vids.myspace.com/index.cfm?fuseaction=vids.individual&videoid=1319998686
			// http://myspacetv.com/index.cfm?fuseaction=vids.individual&videoid=9211691
			// <embed src="http://lads.myspace.com/videos/vplayer.swf" flashvars="m=1319998686&type=video" type="application/x-shockwave-flash" width="430" height="346"></embed>
			
			// find video: and grab the id
			var pos = href.toLowerCase().indexOf('videoid=');
			if (pos == -1) { continue; }
			pos += 8;
			
			// get the video's id	
			var videoId = href.substr(pos);
			videoId = videoId.split('&');
			videoId = videoId[0];
			
			// create a container for the video 
			var el = doc.createElement('embed');
			el.setAttribute('style', 'display: block;');
			el.setAttribute('width', '430');
			el.setAttribute('height', '346');
			el.setAttribute('src', 'http://lads.myspace.com/videos/vplayer.swf');
			el.setAttribute('type', 'application/x-shockwave-flash');
			el.setAttribute('flashvars', 'm=' + videoId + '&type=video');
		}
		else if (bSuperDeluxe)
		{
			// http://www.superdeluxe.com/sd/contentDetail.do?id=D81F2344BF5AC7BB4150694B68D7CBDECD182E9D6429469D
			// <object width="400" height="350"><param name="allowFullScreen" value="true" /><param name="movie" value="http://www.superdeluxe.com/static/swf/share_vidplayer.swf" /><param name="FlashVars" value="id=D81F2344BF5AC7BB4150694B68D7CBDECD182E9D6429469D" /><embed src="http://www.superdeluxe.com/static/swf/share_vidplayer.swf" FlashVars="id=D81F2344BF5AC7BB4150694B68D7CBDECD182E9D6429469D" type="application/x-shockwave-flash" width="400" height="350" allowFullScreen="true" ></embed></object>
			
			// find video: and grab the id
			var pos = href.indexOf('id=');
			if (pos == -1) { continue; }
			pos += 3;
			
			// get the video id
			var videoId = href.substr(pos);
			videoId = videoId.split('&');
			videoId = videoId[0];
			
			// create a container for the video 
			var el = doc.createElement('object');
			el.setAttribute('style', 'display: block;');
			el.setAttribute('width', '400');
			el.setAttribute('height', '350');
			
			el.appendChild(createParam(doc, 'allowFullScreen', 'true'));
			el.appendChild(createParam(doc, 'movie', 'http://www.superdeluxe.com/static/swf/share_vidplayer.swf'));
			el.appendChild(createParam(doc, 'FlashVars', 'id=' + videoId));
			
			var em = doc.createElement('embed');
			em.setAttribute('src', 'http://www.superdeluxe.com/static/swf/share_vidplayer.swf');
			em.setAttribute('FlashVars', 'id=D81F2344BF5AC7BB4150694B68D7CBDECD182E9D6429469D');
			em.setAttribute('type', 'application/x-shockwave-flash');
			em.setAttribute('width', '400');
			em.setAttribute('height', '350');
			em.setAttribute('allowFullScreen', 'true');
			
			el.appendChild(em);
		}
		
		else if (bGameTrailers)
		{
			// http://www.gametrailers.com/player/21690.html
			// <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" id="gtembed" width="480" height="409">	<param name="allowScriptAccess" value="sameDomain" /> <param name="movie" value="http://www.gametrailers.com/remote_wrap.php?mid=20574"/> <param name="quality" value="high" /> <embed src="http://www.gametrailers.com/remote_wrap.php?mid=20574" swLiveConnect="true" name="gtembed" align="middle" allowScriptAccess="sameDomain" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="480" height="409"></embed> </object>
			
			// find video: and grab the id
			var pos = href.indexOf('/player/');
			if (pos == -1) { continue; }
			pos += 8;
			
			// get the video id
			var videoId = href.substr(pos);
			videoId = videoId.split('.');
			videoId = videoId[0];
			
			// create a container for the video 
			var el = doc.createElement('object');
			el.setAttribute('classid', 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000');
			el.setAttribute('codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0');
			el.setAttribute('id', 'gtembed');
			el.setAttribute('style', 'display: block; margin: 10px 0;');
			el.setAttribute('width', '480');
			el.setAttribute('height', '409');
			
			el.appendChild(createParam(doc, 'allowScriptAccess', 'sameDomain'));
			el.appendChild(createParam(doc, 'movie', 'http://www.gametrailers.com/remote_wrap.php?mid=' + videoId));
			el.appendChild(createParam(doc, 'quality', 'high'));

			var em = doc.createElement('embed');
			em.setAttribute('src', 'http://www.gametrailers.com/remote_wrap.php?mid=' + videoId);
			em.setAttribute('swLiveConnect', 'true');
			em.setAttribute('name', 'gtembed');
			em.setAttribute('align', 'middle');
			em.setAttribute('allowScriptAccess', 'sameDomain');
			em.setAttribute('quality', 'high');
			em.setAttribute('pluginspage', 'http://www.macromedia.com/go/getflashplayer');
			em.setAttribute('type', 'application/x-shockwave-flash');
			em.setAttribute('width', '480');
			em.setAttribute('height', '409');
			
			el.appendChild(em);
		}
		else if (bGamespot)
		{
			// http://www.gamespot.com/video/0/6174766/videoplayerpop?rgroup=e32007_live
			// <embed id="mymovie" width="432" height="355" flashvars="paramsURI=http%3A%2F%2Fwww%2Egamespot%2Ecom%2Fpages%2Fvideo%5Fplayer%2Fproteus%5Fxml%2Ephp%3Fadseg%3D741782%26adgrp%3D11765%26sid%3D6174766%26pid%3D939217%26nc%3D1184351152211%26embedded%3D1&showWatermark=0&autoPlay=0" allowfullscreen="true" allowscriptaccess="always" quality="high" name="mymovie" src="http://image.com.com/gamespot/images/cne_flash/production/media_player/proteus/gs/proteus_embed.swf" type="application/x-shockwave-flash"/>			
			
			// find video: and grab the id
			var pos = href.indexOf('/video/0/');
			if (pos == -1) { continue; }
			pos += 9;
			
			// get the video's id	
			var videoId = href.substr(pos);
			videoId = videoId.split('/');
			videoId = videoId[0];
			
			// create a container for the video 
			var el = doc.createElement('embed');
			el.setAttribute('style', 'display: block;');
			el.setAttribute('id', 'mymovie');
			el.setAttribute('width', '432');
			el.setAttribute('height', '355');
			el.setAttribute('flashvars', 'paramsURI=http%3A%2F%2Fwww%2Egamespot%2Ecom%2Fpages%2Fvideo%5Fplayer%2Fproteus%5Fxml%2Ephp%3Fadseg%3D741782%26adgrp%3D11765%26sid%3D' + videoId + '%26pid%3D939217%26nc%3D1184351152211%26embedded%3D1&showWatermark=0&autoPlay=0');
			el.setAttribute('allowfullscreen', 'true');
			el.setAttribute('allowscriptaccess', 'always');
			el.setAttribute('quality', 'high');
			el.setAttribute('name', 'mymovie');
			el.setAttribute('src', 'http://image.com.com/gamespot/images/cne_flash/production/media_player/proteus/gs/proteus_embed.swf');
			el.setAttribute('type', 'application/x-shockwave-flash');
		}
		else if (bGamevideos)
		{
			// http://www.gamevideos.com/video/id/13378
			// <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="420" height="405" id="gamevideos6" align="middle"><param name="quality" value="high"><param name="play" value="true"><param name="loop" value="true"><param name="scale" value="showall"><param name="wmode" value="window"><param name="devicefont" value="false"><param name="bgcolor" value="#000000"><param name="menu" value="true"><param name="allowScriptAccess" value="sameDomain"><param name="allowFullScreen" value="true"><param name="salign" value=""><param name="movie" value="http://www.gamevideos.com:80/swf/gamevideos11.swf?embedded=1&fullscreen=1&autoplay=0&src=http://www.gamevideos.com:80/video/videoListXML%3Fid%3D13378%26ordinal%3D1185303726427%26adPlay%3Dfalse" /><param name="quality" value="high" /><param name="bgcolor" value="#000000" /> <embed src="http://www.gamevideos.com:80/swf/gamevideos11.swf?embedded=1&fullscreen=1&autoplay=0&src=http://www.gamevideos.com:80/video/videoListXML%3Fid%3D13378%26ordinal%3D1185303726427%26adPlay%3Dfalse" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" play="true" loop="true" scale="showall" wmode="window" devicefont="false" id="gamevideos6" bgcolor="#000000" name="gamevideos6" menu="true" allowscriptaccess="sameDomain" allowFullScreen="true" type="application/x-shockwave-flash" align="middle" height="405" width="420"/></object>			
			
			// find video: and grab the id
			var pos = href.indexOf('/video/id/');
			if (pos == -1) { continue; }
			pos += 10;
			
			// get the video's id	
			var videoId = href.substr(pos);
			videoId = videoId.split('/');
			videoId = videoId[0];
			
			// create a container for the video 
			var el = doc.createElement('object');
			el.setAttribute('style', 'display: block; margin: 10px 0 20px 0;');
			el.setAttribute('classid', "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000");
			el.setAttribute('codebase', "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0");
			el.setAttribute('width', '420');
			el.setAttribute('height', '405');
			el.setAttribute('align', 'middle');
			
			el.appendChild(createParam(doc, 'quality', 'high'));
			el.appendChild(createParam(doc, 'play', 'true'));
			el.appendChild(createParam(doc, 'loop', 'true'));
			el.appendChild(createParam(doc, 'scale', 'showall'));
			el.appendChild(createParam(doc, 'wmode', 'window'));
			el.appendChild(createParam(doc, 'devicefont', 'false'));
			el.appendChild(createParam(doc, 'quality', 'high'));
			el.appendChild(createParam(doc, 'bgcolor', '#000000'));
			el.appendChild(createParam(doc, 'meun', 'true'));
			el.appendChild(createParam(doc, 'allowScriptAccess', 'sameDomain'));
			el.appendChild(createParam(doc, 'allowFullScreen', 'true'));
			el.appendChild(createParam(doc, 'salign', ''));
			el.appendChild(createParam(doc, 'movie', 'http://www.gamevideos.com:80/swf/gamevideos11.swf?embedded=1&fullscreen=1&autoplay=0&src=http://www.gamevideos.com:80/video/videoListXML%3Fid%3D' + videoId + '%26ordinal%3D1185303726427%26adPlay%3Dfalse'));
			
			var em = doc.createElement('embed');
			em.setAttribute('src', 'http://www.gamevideos.com:80/swf/gamevideos11.swf?embedded=1&fullscreen=1&autoplay=0&src=http://www.gamevideos.com:80/video/videoListXML%3Fid%3D' + videoId + '%26ordinal%3D1185303726427%26adPlay%3Dfalse');
			em.setAttribute('quality', 'high');
			em.setAttribute('pluginspage', 'http://www.macromedia.com/go/getflashplayer');
			em.setAttribute('play', 'true');
			em.setAttribute('loop', 'true');
			em.setAttribute('scale', 'showall');
			em.setAttribute('wmode', 'window');
			em.setAttribute('devicefont', 'false');
			em.setAttribute('bgcolor', '#000000');
			em.setAttribute('name', '6');
			em.setAttribute('menu', 'true');
			em.setAttribute('allowscriptaccess', 'sameDomain');
			em.setAttribute('allowFullScreen', 'true');
			em.setAttribute('type', 'application/x-shockwave-flash');
			em.setAttribute('align', 'middle');
			em.setAttribute('width', '405');
			em.setAttribute('height', '420');
			
			el.appendChild(em);
		}
		else if (bAdultSwim)
		{
			// http://www.adultswim.com/video/?episodeID=8a25c392167bf53f01167c7fabae0005
			// <object width="425" height="350" type="application/x-shockwave-flash" data="http://www.adultswim.com/video/vplayer/index.html"><param name="allowFullScreen" value="true" /><param name="movie" value="http://www.adultswim.com/video/vplayer/index.html"/><param name="FlashVars" value="id=8a25c392167bf53f01167c7fabae0005" /><embed src="http://www.adultswim.com/video/vplayer/index.html" type="application/x-shockwave-flash" FlashVars="id=8a25c392167bf53f01167c7fabae0005" allowFullScreen="true" width="425" height="350"></embed></object>
			
			// find video: and grab the id
			var str = '/video/?episodeID=';
			var pos = href.indexOf(str);
			if (pos == -1) { continue; }
			pos += str.length;
			
			// get the video's id	
			var videoId = href.substr(pos);
			videoId = videoId.split('&');
			videoId = videoId[0];
			
			// create a container for the video 
			var el = doc.createElement('object');
			el.setAttribute('style', 'display: block; margin: 10px 0 20px 0;');
			el.setAttribute('width', '425');
			el.setAttribute('height', '350');
			el.setAttribute('type', 'application/x-shockwave-flash');
			el.setAttribute('data', 'http://www.adultswim.com/video/vplayer/index.html');
			
			el.appendChild(createParam(doc, 'allowFullScreen', 'true'));
			el.appendChild(createParam(doc, 'movie', 'http://www.adultswim.com/video/vplayer/index.html'));
			el.appendChild(createParam(doc, 'FlashVars', 'id=' + videoId));
			
			var em = doc.createElement('embed');
			em.setAttribute('src', 'http://www.adultswim.com/video/vplayer/index.html');
			em.setAttribute('type', 'application/x-shockwave-flash');
			em.setAttribute('FlashVars', 'id=' + videoId);
			em.setAttribute('allowFullScreen', 'true');
			em.setAttribute('width', '425');
			em.setAttribute('height', '350');
			
			el.appendChild(em);
		}
		else if (bVideoMsn)
		{
			// http://video.msn.com/video.aspx?mkt=en-us&tab=soapbox&vid=8557ab3e-8eca-49a1-98da-dbf2060e562c
			// <embed src="http://images.video.msn.com/flash/soapbox1_1.swf" quality="high" width="432" height="364" base="http://images.video.msn.com" type="application/x-shockwave-flash" allowFullScreen="true" pluginspage="http://macromedia.com/go/getflashplayer" flashvars="c=v&v=8557ab3e-8eca-49a1-98da-dbf2060e562c&ifs=true&fr=msnvideo&mkt=en-US&brand="></embed>
			
			// find video: and grab the id
			var str = 'vid=';
			var pos = href.indexOf(str);
			if (pos == -1) { continue; }
			pos += str.length;
			
			// get the video's id	
			var videoId = href.substr(pos);
			videoId = videoId.split('&');
			videoId = videoId[0];
			
			var el = doc.createElement('embed');
			el.setAttribute('style', 'display: block;');
			el.setAttribute('src', 'http://images.video.msn.com/flash/soapbox1_1.swf');
			el.setAttribute('quality', 'high');
			el.setAttribute('width', '432');
			el.setAttribute('height', '364');
			el.setAttribute('base', 'http://images.video.msn.com');
			el.setAttribute('type', 'application/x-shockwave-flash');
			el.setAttribute('allowFullScreen', 'true');
			el.setAttribute('pluginspage', 'http://macromedia.com/go/getflashplayer');
			el.setAttribute('flashvars', 'c=v&v=' + videoId + '&ifs=true&fr=msnvideo&mkt=en-US&brand=');
			
		}
		else if (bRockstar)
		{		
			// https://tv.rockstargames.com/videos/view/id/757BD25A1FBA9DEF
			// <object width="496" height="320"><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><param name="movie" value="https://rsgames.hs.llnwd.net/o10/ZTM1MTNmMmVjYjRhNWViNWQ3ZmZhOGUyMDI2OGJlYzY=/swf/EmbedVideoPlayer_wide.swf?asset_key=757BD25A1FBA9DEF&baseUrl=https://tv.rockstargames.com/"></param><embed src="https://rsgames.hs.llnwd.net/o10/ZTM1MTNmMmVjYjRhNWViNWQ3ZmZhOGUyMDI2OGJlYzY=/swf/EmbedVideoPlayer_wide.swf?asset_key=757BD25A1FBA9DEF&baseUrl=https://tv.rockstargames.com/" allowscriptaccess="always" allowfullscreen="true" type="application/x-shockwave-flash" width="496" height="320"></embed></object>

			var arr = href.split('/'); 
			var videoId = arr[arr.length - 1]; 
			
			// create a container for the video 
			var el = doc.createElement('object');
			el.style.display = 'block';
			el.setAttribute('width', '496'); 
			el.setAttribute('height', '320');
			el.appendChild(createParam(doc, 'allowFullScreen', 'true'));
			el.appendChild(createParam(doc, 'allowscriptaccess', 'always'));
			el.appendChild(createParam(doc, 'movie', 'https://rsgames.hs.llnwd.net/o10/ZTM1MTNmMmVjYjRhNWViNWQ3ZmZhOGUyMDI2OGJlYzY=/swf/EmbedVideoPlayer_wide.swf?asset_key=' + videoId + '&baseUrl=https://tv.rockstargames.com/'));

			var em = doc.createElement('embed');
			em.setAttribute('src', 'https://rsgames.hs.llnwd.net/o10/ZTM1MTNmMmVjYjRhNWViNWQ3ZmZhOGUyMDI2OGJlYzY=/swf/EmbedVideoPlayer_wide.swf?asset_key=' + videoId + '&baseUrl=https://tv.rockstargames.com/');
			em.setAttribute('allowscriptaccess', 'always');
			em.setAttribute('allowfullscreen', 'true');
			em.setAttribute('type', 'application/x-shockwave-flash');
			em.setAttribute('width', '496');
			em.setAttribute('height', '320');
			
			el.appendChild(em);
		}
		else if (bBreakVid)
		{
			/*
			
			Break is tricky because its URL doesn't contain the video id needed for the embedded player.  There
			are other sites that do this as well, so I thought I'd have to figure this out eventually. 

			I NEED TO PASS A REFERENCE TO THE ANCHOR OBJECT TO THE SCRIPT, OR DO SOMETHING ELSE THAT WILL LET THE SCRIPT INSERT 
			THE OBJECT INTO THE RIGHT PLACE
			
			I'M CREATING A DIV TO INSERT THE VIDEO INTO, BUT NOW I HAVE TO ADD CODE TO THE XMLHTTP ROUTINE TO FIGURE OUT
			WHAT THE HTML VIDEO NAME WAS TO KNOW WHERE TO INSERT THE VIDEO
			
			If someone wants this to work, most of the tough stuff is done. haha
			
			*/
			
			continue; 


			// link:  http://www.break.com/index/slightly_over_excited.html
			// embed: <object width="425" height="350"><param name="movie" value="http://embed.break.com/MTgxMTU1"></param><embed src="http://embed.break.com/MTgxMTU1" type="application/x-shockwave-flash" width="425" height="350"></embed></object>

			// find video: and grab the id
			var pos = href.indexOf('/index/');
			if (pos == -1) { continue; }
			
			// get the video's id	
			var videoId = href.substr(pos + 7);
			
			// drop the .html
			videoId = videoId.split('.')[0];			

			// make a new element to contain our xmlhttp'd object when it loads
			var el = doc.createElement('div');
			el.setAttribute('style', 'display: block; width: 425px; height: 350px;');
			el.setAttribute('id', videoId);

			GM_xmlhttpRequest({
				method: 'GET',
				url: href,
				headers: {
					'User-agent': 'Mozilla/4.0 (compatible) Greasemonkey',
				},
				onload: function(responseDetails) {
					
					// find videoId buried in the HTML
					
					// find the input control containing the embedded video id 
					var pos = responseDetails.responseText.indexOf('<input type="text" name="EmbedTextBox"');
					if (pos == -1) { TW_log('could not find EmbedTextBox');  return; }
					
					// find the value property
					pos = responseDetails.responseText.indexOf('value="', pos);
					if (pos == -1) 
					{ 
						TW_log('could not find EmbedTextBox value="'); 
						return; 
					}
					else
					{
						pos += 7;
					}

					var pos2 = responseDetails.responseText.indexOf('"', pos);
					if (pos2 == -1) { TW_log('could not find end of EmbedTextBox value="'); return; }
					
					// convert pos2 to length
					pos2 = (pos2) - pos;
					
					var videoId = responseDetails.responseText.substr(pos + 7, pos2);
					
					TW_log('EmbedTextBox value= ' + videoId);
					
					// at this point, videoId should look something like this ugly ass thing: 
					// &lt;object width=&quot;425&quot; height=&quot;350&quot;&gt;&lt;param name=&quot;movie&quot; value=&quot;http://embed.break.com/MTgxMTU1&quot;&gt;&lt;/param&gt;&lt;embed src=&quot;http://embed.break.com/MTgxMTU1&quot; type=&quot;application/x-shockwave-flash&quot; width=&quot;425&quot; height=&quot;350&quot;&gt;&lt;/embed&gt;&lt;/object&gt;
					
					// find value=&quot;
					pos = videoId.indexOf('value=&quot;http://embed.break.com/');
					if (pos == -1) { return; } else { pos += 35; }
					pos2 = videoId.indexOf('&quot;', pos);
					if (pos2 == -1) { return; }
					
					// convert pos2 to length
					pos2 = pos2 - pos;
					
					videoId = videoId.substr(pos, pos2);
					
					TW_log('videoId = ' + videoId);

					// create a container for the video 
					var el = doc.createElement('object');
					el.style.display = 'block';
					el.setAttribute('width', '425');
					el.setAttribute('height', '350');
					
					// <param name="movie" value="http://embed.break.com/MTgxMTU1"></param>
					var pa1 = doc.createElement('param');
					pa1.setAttribute('name', 'movie');
					pa1.setAttribute('value', 'http://embed.break.com/' + videoId);
					
					// <embed src="http://embed.break.com/MTgxMTU1" type="application/x-shockwave-flash" width="425" height="350"></embed>
					var em = doc.createElement('embed');
					em.setAttribute('src', 'http://embed.break.com/' + videoId);
					em.setAttribute('type', 'application/x-shockwave-flash');
					em.setAttribute('width', '425');
					em.setAttribute('height', '350');
					
					el.appendChild(pa1);
					el.appendChild(em);
					
					// doc.getElementById
				}
			});			
		}

		// insert the video before the anchor
		if (typeof(el) != 'undefined') 
		{ 
			a[i].parentNode.insertBefore(el, a[i]);
		}
	}
}


function toggleNws()
{
	// read value and toggle state 
	var bool = GM_getValue('embedNws', true);
	bool = (bool == false);
	GM_setValue('embedNws', bool);
	
	// display message to user
	var state = bool ? '' : 'NOT'; 
	alert('Video Embedinator will ' + state + ' embed videos in NWS posts');
}

	if (String(location).indexOf('shacknews.com/laryn.x?') != -1)
	{
		/*
		var embedNws = GM_getValue('embedNws', true);
		
		// Add menu option(s) to the Greasemonkey menu
		GM_registerMenuCommand('Video Embedinator: Toggle NWS embedination', toggleNws);
		*/
		
		// override standard show_item_fullpost with one that supports this script
		if (!unsafeWindow.yte_show_item_fullpost)
		{
			unsafeWindow.yte_show_item_fullpost = unsafeWindow.show_item_fullpost;
			unsafeWindow.show_item_fullpost = function(root_id, article_id, fullpost_element)
			{
				// call original function 
				unsafeWindow.yte_show_item_fullpost(root_id, article_id, fullpost_element);
				
				thomwEmbedVideos(document.getElementById('item_' + article_id));
			}
		}
				
		// find all the parent divs that have anchors
		var divs = getElementsByClassName('fullpost', 'div', getElementByClassName(document, 'div', 'threads'));

		// run through the root divs and collect their anchors
		var as = new Array();
		for (var i = 0; i < divs.length; i++)
		{
			// just grabs anchors inside postbodies 
			var a2 = getElementByClassName(divs[i], 'div', 'postbody').getElementsByTagName('a');
			for (var j = 0; j < a2.length; j++)
			{
				as.push(a2[j]);
			}
		}
		
		// run the embed routine on the anchors that were found -- 
		// this should be a lot faster than looking at every anchor on the page
		thomwEmbedVideos(as);
	}
	else if (String(location).indexOf('shacknews.com/frame_laryn.x?') != -1)
	{
		// override standard show_item_fullpost with one that supports this script
		if (!unsafeWindow.yte_show_item_fullpost)
		{
			unsafeWindow.yte_show_item_fullpost = unsafeWindow.show_item_fullpost;
			unsafeWindow.show_item_fullpost = function(root_id, article_id, fullpost_element)
			{
				TW_log('yte_show_item_fullpost (root_id=' + root_id + ', article_id=' + article_id + ')');
				
				// call original function 
				unsafeWindow.yte_show_item_fullpost(root_id, article_id, fullpost_element);

				// embed videos in updated parent window
				thomwEmbedVideos(unsafeWindow.top.document.getElementById('item_' + article_id));
			}
		}
		
		// override function used for Refresh Thread button
		if (!unsafeWindow.yte_replace_whole_element_from_iframe)
		{
			unsafeWindow.yte_replace_whole_element_from_iframe = unsafeWindow.replace_whole_element_from_iframe;
			unsafeWindow.replace_whole_element_from_iframe = function(id)
			{
				TW_log('yte_replace_whole_element_from_iframe (id=' + id + ')');
				
				// call the original function
				unsafeWindow.yte_replace_whole_element_from_iframe(id);
				
				// set doc
				doc = unsafeWindow.top.document;
				
				// find all the parent divs that have anchors
				var divs = getElementsByClassName('fullpost', 'div', doc.getElementById(id));
				
				// run through the root divs and collect their anchors
				var as = new Array();
				for (var i = 0; i < divs.length; i++)
				{
					// search postbody for anchors 
					var a2 = getElementByClassName(divs[i], 'div', 'postbody').getElementsByTagName('a');
					for (var j = 0; j < a2.length; j++)
					{
						as.push(a2[j]);
					}
				}
				
				// run the embed routine on the anchors that were found -- 
				// this should be a lot faster than looking at every anchor on the page
				thomwEmbedVideos(as);
			}
		}

	}
	/*
	
	// obsolete old shack code 
	
	else if (String(location).indexOf('shacknews.com/ja.zz?') != -1)
	{
		// override standard dComment with one that supports my little hack
		unsafeWindow.thomwDComment = unsafeWindow.dComment;
		unsafeWindow.dComment = function(commentID, showInID)
		{
			// call original function 
			unsafeWindow.thomwDComment(commentID, showInID);
			
			// check success condition of dComment before firing script
			if (unsafeWindow.tryAgain == false) 
			{
				thomwEmbedVideos(document.getElementById("threadblock"+showInID ));
			}
		}

		// scan document for videos 
		thomwEmbedVideos(document);
	}
	*/
	else if ((String(location).indexOf('stoofoo.net/chatty.x') != -1) || (String(location).indexOf('stoofoo.net/handler.x') != -1))
	{
		doc = unsafeWindow.top.document;

		var as = new Array();
		var items = doc.evaluate("//td[@class='cmt-body']", doc, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
		for (item = null, i = 0; item = items.snapshotItem(i); i++)
		{
			if (item.className.indexOf('embedinated') != -1)
			{
				continue;
			}
			
			// just grabs anchors inside postbodies 
			var a2 = item.getElementsByTagName('a');
			for (var j = 0; j < a2.length; j++)
			{
				as.push(a2[j]);
			}
			
			item.className += ' embedinated';
		}

		// run the embed routine on the anchors that were found -- 
		// this should be a lot faster than looking at every anchor on the page
		thomwEmbedVideos(as);
	}
	else
	{
		// scan document for videos 
		thomwEmbedVideos(document);
	}
	
	// log execution time
	TW_log((getTime() - scriptStartTime) + 'ms');
	
})();