tinyMCEPopup.requireLangPack();

var embedded_videoDialog = {
    
	init : function() {
		var f = document.forms[0];
	},

	insert : function() {
		// Insert the contents from the input into the document
		
		var strHtml  = '';
		var portal  = document.forms[0].portal.value;
		var vid    = document.forms[0].vid.value;
		var nolink   = document.forms[0].nolink.checked;
		var linktext = document.forms[0].linktext.value;
	
        
		if(!nolink){
			switch (portal) {
			case "youtube":
				strHtml = "<a title=\"YouTube\" href=\"http://www.youtube.com/watch?v=###VID###\">###TXT######THING###</a>";
				break;
			case "google":
				strHtml =  "<a title=\"Google Video\" href=\"http://video.google.com/videoplay?docid=###VID###\">###TXT######THING###</a>";
				break;
			case "myspace":
				strHtml = "<a title=\"MySpace Video\" href=\"http://vids.myspace.com/index.cfm?fuseaction=vids.individual&amp;videoid=###VID###\">###TXT######THING###</a>";
				break;
			case "revver":
				strHtml = "<a title=\"Revver\" href=\"http://one.revver.com/watch/###VID###\">###TXT######THING###</a>";
				break;
			case "sevenload":
				strHtml = "<a title=\"Sevenload\" href=\"http://sevenload.com/videos/###VID###\">###TXT######THING###</a>";
				break;
			case "clipfish":
				strHtml = "<a title=\"Clipfish\" href=\"http://www.clipfish.de/player.php?videoid=###VID###\">###TXT######THING###</a>";
				break;
			case "metacafe":
				strHtml = "<a title=\"Metacaf&eacute;\" href=\"http://www.metacafe.com/watch/###VID###\">###TXT######THING###</a>";
				break;
			case "myvideo":
				strHtml = "<a title=\"MyVideo\" href=\"http://www.myvideo.de/watch/###VID###\">###TXT######THING###</a>";
				break;
			case "yahoo":
				strHtml = "<a title=\"Yahoo! Video\" href=\"http://video.yahoo.com/video/play?vid=###YAHOO###.###VID###\">###TXT######THING###</a>";
				break;
			case "ifilm":
				strHtml = "<a title=\"ifilm\" href=\"http://www.ifilm.com/video/###VID###\">###TXT######THING###</a>";
				break;
			case "brightcove":
				strHtml = "<a title=\"brightcove\" href=\"http://www.brightcove.com/title.jsp?title=###VID###\">###TXT######THING###</a>";
				break;
			case "aniboom":
				strHtml = "<a title=\"aniBOOM\" href=\"http://www.aniboom.com/Player.aspx?v=###VID###\">###TXT######THING###</a>";
				break;
			case "vimeo":
				strHtml = "<a title=\"vimeo\" href=\"http://www.vimeo.com/clip:###VID###\">###TXT######THING###</a>";
				break;
			case "guba":
				strHtml = "<a title=\"GUBA\" href=\"http://www.guba.com/watch/###VID###\">###TXT######THING###</a>";
				break;
			case "gamevideo":
				strHtml = "<a title=\"GameVideos\" href=\"http://gamevideos.com/video/id/###VID###\">###TXT######THING###</a>";
				break;
			case "vsocial":
				strHtml = "<a title=\"vSocial\" href=\"http://www.vsocial.com/video/?d=###VID###\">###TXT######THING###</a>";
				break;
			case "veoh":
				strHtml = "<a title=\"Veoh\" href=\"http://www.veoh.com/videos/###VID###\">###TXT######THING###</a>";
				break;
			case "gametrailers":
				strHtml = "<a title=\"Gametrailers\" href=\"http://www.gametrailers.com/player/###VID###.html\">###TXT######THING###</a>";
				break;
			default:
				break;
			}
			
			
		} else {
			var general_width = 425;
			var YOUTUBE_HEIGHT = Math.floor(general_width*14/17);
			var GOOGLE_HEIGHT = Math.floor(general_width*14/17);
			var MYVIDEO_HEIGHT = Math.floor(general_width*367/425);
			var CLIPFISH_HEIGHT = Math.floor(general_width*95/116);
			var SEVENLOAD_HEIGHT = Math.floor(general_width*408/500);
			var REVVER_HEIGHT = Math.floor(general_width*49/60);
			var METACAFE_HEIGHT = Math.floor(general_width*69/80);
			var YAHOO_HEIGHT = Math.floor(general_width*14/17);
			var IFILM_HEIGHT = Math.floor(general_width*365/448);
			var MYSPACE_HEIGHT = Math.floor(general_width*173/215);
			var BRIGHTCOVE_HEIGHT = Math.floor(general_width*206/243);
			var QUICKTIME_HEIGHT = Math.floor(general_width*3/4);
			var VIDEO_HEIGHT = Math.floor(general_width*3/4);
			var ANIBOOM_HEIGHT = Math.floor(general_width*93/112);
			var FLASHPLAYER_HEIGHT = Math.floor(general_width*93/112);
			var VIMEO_HEIGHT = Math.floor(general_width*3/4);
			var GUBA_HEIGHT = Math.floor(general_width*72/75);
			var DAILYMOTION_HEIGHT = Math.floor(general_width*334/425);
			var GARAGE_HEIGHT = Math.floor(general_width*289/430);
			var GAMEVIDEO_HEIGHT = Math.floor(general_width*3/4);
			var VSOCIAL_HEIGHT = Math.floor(general_width*40/41);
			var VEOH_HEIGHT = Math.floor(general_width*73/90);
			var GAMETRAILERS_HEIGHT = Math.floor(general_width*392/480);
			switch (portal) {
			case "youtube":
				strHtml = "<object type=\"application/x-shockwave-flash\" data=\"http://www.youtube.com/v/###VID###\" width=\""+general_width+"\" height=\""+YOUTUBE_HEIGHT+"\"><param name=\"movie\" value=\"http://www.youtube.com/v/###VID###\" /><param name=\"autostart\" value=\"true\" /><param name=\"wmode\" value=\"transparent\" /></object><br />";
				break;
			case "google":
				strHtml = "<object type=\"application/x-shockwave-flash\" data=\"http://video.google.com/googleplayer.swf?docId=###VID###\" width=\""+general_width+"\" height=\""+GOOGLE_HEIGHT+"\"><param name=\"movie\" value=\"http://video.google.com/googleplayer.swf?docId=###VID###\" /><param name=\"wmode\" value=\"transparent\" /></object><br />";
				break;
			case "myspace":
				strHtml = "<object type=\"application/x-shockwave-flash\" data=\"http://lads.myspace.com/videos/vplayer.swf?m=###VID###&amp;type=video\" width=\""+general_width+"\" height=\""+MYSPACE_HEIGHT+"\"><param name=\"movie\" value=\"http://lads.myspace.com/videos/vplayer.swf?m=###VID###&amp;type=video\" /><param name=\"wmode\" value=\"transparent\" /></object><br />";
				break;
			case "revver":
				strHtml = "<object type=\"application/x-shockwave-flash\" data=\"http://flash.revver.com/player/1.0/player.swf?mediaId=###VID###\" width=\""+general_width+"\" height=\""+REVVER_HEIGHT+"\"><param name=\"movie\" value=\"http://flash.revver.com/player/1.0/player.swf?mediaId=###VID###\" /><param name=\"wmode\" value=\"transparent\" /></object><br />";
				break;
			case "sevenload":
				strHtml = "<script type='text/javascript' src='http://sevenload.com/pl/###VID###/"+general_width+"x"+SEVENLOAD_HEIGHT+"'></script><br />";
				break;
			case "clipfish":
				strHtml = "<object type=\"application/x-shockwave-flash\" data=\"http://www.clipfish.de/videoplayer.swf?as=0&amp;videoid=###VID###&amp;r=1\" width=\""+general_width+"\" height=\""+CLIPFISH_HEIGHT+"\"><param name=\"movie\" value=\"http://www.clipfish.de/videoplayer.swf?as=0&amp;videoid=###VID###&amp;r=1\" /><param name=\"wmode\" value=\"transparent\" /></object><br />";
				break;
			case "metacafe":
				strHtml = "<object type=\"application/x-shockwave-flash\" data=\"http://www.metacafe.com/fplayer/###VID###.swf\" width=\""+general_width+"\" height=\""+METACAFE_HEIGHT+"\"><param name=\"movie\" value=\"http://www.metacafe.com/fplayer/###VID###.swf\" /><param name=\"wmode\" value=\"transparent\" /></object><br />";
				break;
			case "myvideo":
				strHtml = "<object type=\"application/x-shockwave-flash\" data=\"http://www.myvideo.de/movie/###VID###\" width=\""+general_width+"\" height=\""+MYVIDEO_HEIGHT+"\"><param name=\"movie\" value=\"http://www.myvideo.de/movie/###VID###\" /><param name=\"wmode\" value=\"transparent\" /></object><br />";
				break;
			case "yahoo":
				strHtml = "<object type=\"application/x-shockwave-flash\" data=\"http://us.i1.yimg.com/cosmos.bcst.yahoo.com/player/media/swf/FLVVideoSolo.swf?id=###VID###\" width=\""+general_width+"\" height=\""+YAHOO_HEIGHT+"\"><param name=\"movie\" value=\"http://us.i1.yimg.com/cosmos.bcst.yahoo.com/player/media/swf/FLVVideoSolo.swf?id=###VID###\" /><param name=\"wmode\" value=\"transparent\" /></object><br />";
				break;
			case "ifilm":
				strHtml = "<object type=\"application/x-shockwave-flash\" data=\"http://www.ifilm.com/efp?flvbaseclip=###VID###\" width=\""+general_width+"\" height=\""+IFILM_HEIGHT+"\"><param name=\"movie\" value=\"http://www.ifilm.com/efp?flvbaseclip=###VID###\" /><param name=\"wmode\" value=\"transparent\" /></object><br />";
				break;
			case "brightcove":
				strHtml = "<object type=\"application/x-shockwave-flash\" data=\"http://admin.brightcove.com/destination/player/player.swf?initVideoId=###VID###&amp;servicesURL=http://services.brightcove.com/services&amp;viewerSecureGatewayURL=https://services.brightcove.com/services/amfgateway&amp;cdnURL=http://admin.brightcove.com&amp;autoStart=false\" width=\""+general_width+"\" height=\""+BRIGHTCOVE_HEIGHT+"\"><param name=\"movie\" value=\"http://admin.brightcove.com/destination/player/player.swf?initVideoId=###VID###&amp;servicesURL=http://services.brightcove.com/services&amp;viewerSecureGatewayURL=https://services.brightcove.com/services/amfgateway&amp;cdnURL=http://admin.brightcove.com&amp;autoStart=false\" /><param name=\"wmode\" value=\"transparent\" /></object><br />";
				break;
			case "aniboom":
				strHtml = "<object type=\"application/x-shockwave-flash\" data=\"http://api.aniboom.com/embedded.swf?videoar=###VID###&amp;allowScriptAccess=sameDomain&amp;quality=high\" width=\""+general_width+"\" height=\""+ANIBOOM_HEIGHT+"\"><param name=\"movie\" value=\"http://api.aniboom.com/embedded.swf?videoar=###VID###&amp;allowScriptAccess=sameDomain&amp;quality=high\" /><param name=\"wmode\" value=\"transparent\" /></object><br />";
				break;
			case "vimeo":
				strHtml = "<object type=\"application/x-shockwave-flash\" data=\"http://www.vimeo.com/moogaloop.swf?clip_id=###VID###\" width=\""+general_width+"\" height=\""+VIMEO_HEIGHT+"\"><param name=\"movie\" value=\"http://www.vimeo.com/moogaloop.swf?clip_id=###VID###\" /><param name=\"wmode\" value=\"transparent\" /></object><br />";
				break;
			case "guba":
				strHtml = "<object type=\"application/x-shockwave-flash\" data=\"http://www.guba.com/f/root.swf?video_url=http://free.guba.com/uploaditem/###VID###/flash.flv&amp;isEmbeddedPlayer=true\" width=\""+general_width+"\" height=\""+GUBA_HEIGHT+"\"><param name=\"movie\" value=\"http://www.guba.com/f/root.swf?video_url=http://free.guba.com/uploaditem/###VID###/flash.flv&amp;isEmbeddedPlayer=true\" /><param name=\"wmode\" value=\"transparent\" /></object><br />";
				break;
			case "gamevideo":
				strHtml = "<object type=\"application/x-shockwave-flash\" data=\"http://gamevideos.com:80/swf/gamevideos11.swf?embedded=1&amp;autoplay=0&amp;src=http://gamevideos.com:80/video/videoListXML%3Fid%3D###VID###%26adPlay%3Dfalse\" width=\""+general_width+"\" height=\""+GAMEVIDEO_HEIGHT+"\"><param name=\"movie\" value=\"http://gamevideos.com:80/swf/gamevideos11.swf?embedded=1&fullscreen=1&amp;autoplay=0&amp;src=http://gamevideos.com:80/video/videoListXML%3Fid%3D###VID###%26adPlay%3Dfalse\" /><param name=\"wmode\" value=\"transparent\" /></object><br />";
				break;
			case "vsocial":
				strHtml = "<object type=\"application/x-shockwave-flash\" data=\"http://static.vsocial.com/flash/ups.swf?d=###VID###&a=0\" width=\""+general_width+"\" height=\""+VSOCIAL_HEIGHT+"\"><param name=\"movie\" value=\"http://static.vsocial.com/flash/ups.swf?d=###VID###&a=0\" /><param name=\"wmode\" value=\"transparent\" /></object><br />";
				break;
			case "veoh":
				strHtml = "<object type=\"application/x-shockwave-flash\" data=\"http://www.veoh.com/videodetails2.swf?player=videodetailsembedded&type=v&permalinkId=###VID###&id=anonymous\" width=\""+general_width+"\" height=\""+VEOH_HEIGHT+"\"><param name=\"movie\" value=\"http://www.veoh.com/videodetails2.swf?player=videodetailsembedded&type=v&permalinkId=###VID###&id=anonymous\" /><param name=\"autostart\" value=\"true\" /><param name=\"wmode\" value=\"transparent\" /></object><br />";
				break;
			case "gametrailers":
				strHtml = "<object type=\"application/x-shockwave-flash\" data=\"http://www.gametrailers.com/remote_wrap.php?mid=###VID###\" width=\""+general_width+"\" height=\""+GAMETRAILERS_HEIGHT+"\"><param name=\"movie\" value=\"http://www.gametrailers.com/remote_wrap.php?mid=###VID###\" /><param name=\"autostart\" value=\"true\" /><param name=\"wmode\" value=\"transparent\" /></object><br />";
				break;
			default:
				break;
			}
		}
		strHtml = strHtml.replace(/###VID###/g, vid);
		strHtml = strHtml.replace(/###TXT######THING###/g, linktext);
	
		tinyMCEPopup.editor.execCommand('mceInsertContent', false, strHtml);
		tinyMCEPopup.close();
	}
};

tinyMCEPopup.onInit.add(embedded_videoDialog.init, embedded_videoDialog);

function disable_enable(objCheckbox, objTextfield) {
	objTextfield.disabled = (objCheckbox.checked) ? true : false;
	objTextfield.value = '';
	objTextfield.style.backgroundColor = (objTextfield.disabled) ? '#ccc' : '#fff';
}