﻿/* This script takes the href-attribute from a link with id ieLowRes (if the browser is IE)
 * or otherLowRes (for other browsers), and embeds the video into the element (preferrably a 
 * div) with id moviePlaceHolder. So make sure that the following elements are available on the page:
 *
 * * a-tag with id ieLowRes, containing a link to the movie intended for Internet Explorer (will be embedded with object-tag)
 * * a-tag with id otherLowRes, containing a link to the movie intended for other browsers (will be embedded with embed-tag)
 * * div-tag with id moviePlaceHolder
 * * any tag with id movieTitle
 *
 */
var MovieEmbedder = {
	IE: false,
	
	ShowMovie:function(){
		//only works if browser supports the DOM
		if(!document.getElementById || !document.getElementById("moviePlaceHolder")) return;
		
		var version = 0;
		var importStatus = true;
		var exportStatus = true;
		var movieFileName = "";
		var movieTitle = "";
		var moviePlaceHolder = document.getElementById("moviePlaceHolder");
		var ieheight = 428; // sets the height for video intended for IE
		var iewidth = 640; // sets the width for video intended for IE
		var otherheight = 360; // sets the height for video intended for other browsers
		var otherwidth = 640; // sets the width for video intended for other browsers
						
		if (navigator.appVersion.indexOf("MSIE")!=-1) {
			temp = navigator.appVersion.split("MSIE")
			version = parseFloat(temp[1])
			
			//Detect IE5.5+
			if (version>=5.5) {
				this.IE = true;
			}
		}

		if (this.IE && document.getElementById("ieLowRes"))
		{
			//Get movie filename
			var temp = document.getElementById("ieLowRes");
			movieFileName = temp.getAttribute("href");
			//Get movie title if it exists
			if(document.getElementById("movieTitle")){
				temp = document.getElementById("movieTitle");
				movieTitle = temp.firstChild.nodeValue;
			}
			//Embed with object tag (for IE), innerHTML version
			moviePlaceHolder.innerHTML = '<object id="MediaPlayer1" width="'+iewidth+'" height="'+ieheight+'" standby="Loading Windows Media Player components..." data="'+movieFileName+'" type="application/x-mplayer2" title="'+movieTitle+'" style="background-color: #000000;">'
			+ '<param name="filename" value="'+movieFileName+'">'
			+ '<param name="height" value="'+ieheight+'">'
			+ '<param name="width" value="'+iewidth+'">'
			+ '<param name="autoStart" value="1">'
			+ '<param name="autoPlay" value="1">'
			+ '<param name="AnimationatStart" value="1">'
			+ '<param name="showdisplay" value="0">'
			+ '<param name="TransparentAtStart" value="0">'
			+ '<param name="ShowControls" value="1">'
			+ '<param name="ShowStatusBar" value="1">'
			+ '<param name="ClickToPlay" value="0">'
			+ '<param name="bgcolor" value="#000000">'
			+ '<param name="volume" value="100%">'
			+ '<param name="InvokeURLs" value="0">'
			+ '<param name="loop" value="0">'
			+ '</object>'
			+ '<br><em style="margin: auto">'+movieTitle+', Windows Media Player movie</em>';
			
			/*
			//Embed with object tag (for IE), DOM version
			//Had problems with this one in IE, IE sees a security risk and blocks the ActiveX, so I'm using the innerHTML above instead //Stefan
			var objectTag = document.createElement('object');
			objectTag.setAttribute('id', 'MediaPlayer1');
			objectTag.setAttribute('width', '640');
			objectTag.setAttribute('height', '480');
			objectTag.setAttribute('data', movieFileName);
			objectTag.setAttribute('type', 'application/x-mplayer2');
			//add all params... lots of them
			var paramTag = document.createElement('param');
			paramTag.value = movieFileName;
			paramTag.name = 'filename';
			//paramTag.setAttribute('value', movieFileName);
			//paramTag.setAttribute('name', 'filename');
			objectTag.appendChild(paramTag);
			/*
			var paramTag2 = document.createElement('param');
			paramTag2.setAttribute('name', 'height');
			paramTag2.setAttribute('value', '480');
			objectTag.appendChild(paramTag2);
			
			var paramTag3 = document.createElement('param');
			paramTag3.setAttribute('name', 'width');
			paramTag3.setAttribute('value', '640');
			objectTag.appendChild(paramTag3);
			
			var paramTag4 = document.createElement('param');
			paramTag4.setAttribute('name', 'autoStart');
			paramTag4.setAttribute('value', '1');
			objectTag.appendChild(paramTag4);
			
			var paramTag5 = document.createElement('param');
			paramTag5.setAttribute('name', 'autoPlay');
			paramTag5.setAttribute('value', '1');
			objectTag.appendChild(paramTag5);
			
			var paramTag6 = document.createElement('param');
			paramTag6.setAttribute('name', 'AnimationatStart');
			paramTag6.setAttribute('value', '1');
			objectTag.appendChild(paramTag6);
			
			var paramTag7 = document.createElement('param');
			paramTag7.setAttribute('name', 'showdisplay');
			paramTag7.setAttribute('value', '0');
			objectTag.appendChild(paramTag7);
			
			var paramTag8 = document.createElement('param');
			paramTag8.setAttribute('name', 'TransparentAtStart');
			paramTag8.setAttribute('value', '0');
			objectTag.appendChild(paramTag8);
			
			var paramTag9 = document.createElement('param');
			paramTag9.setAttribute('name', 'ShowControls');
			paramTag9.setAttribute('value', '1');
			objectTag.appendChild(paramTag9);
			
			var paramTag10 = document.createElement('param');
			paramTag10.setAttribute('name', 'ShowStatusBar');
			paramTag10.setAttribute('value', '1');
			objectTag.appendChild(paramTag10);
			
			var paramTag11 = document.createElement('param');
			paramTag11.setAttribute('name', 'ClickToPlay');
			paramTag11.setAttribute('value', '0');
			objectTag.appendChild(paramTag11);
			
			var paramTag12 = document.createElement('param');
			paramTag12.setAttribute('name', 'bgcolor');
			paramTag12.setAttribute('value', '#000000');
			objectTag.appendChild(paramTag12);
			
			var paramTag13 = document.createElement('param');
			paramTag13.setAttribute('name', 'volume');
			paramTag13.setAttribute('value', '100%');
			objectTag.appendChild(paramTag13);
			
			var paramTag14 = document.createElement('param');
			paramTag14.setAttribute('name', 'InvokeURLs');
			paramTag14.setAttribute('value', '0');
			objectTag.appendChild(paramTag14);
			
			var paramTag15 = document.createElement('param');
			paramTag15.setAttribute('name', 'loop');
			paramTag15.setAttribute('value', '0');
			objectTag.appendChild(paramTag15);

			//Add objectTag to page
			moviePlaceHolder.appendChild(objectTag);
			//Remove content intended for those without javascript
			moviePlaceHolder.removeChild(document.getElementById("movieTitle"));
			moviePlaceHolder.removeChild(document.getElementById("movieScreenShot"));
			*/
		}
		else
		{
			//make sure that the script doesn't break if the otherLowRes-element doesn't exist
			if(!document.getElementById("otherLowRes")) return; 
			//Get movie filename
			var temp = document.getElementById("otherLowRes");
			movieFileName = temp.getAttribute("href");
			//Get movie title
			if(document.getElementById("movieTitle")){
				temp = document.getElementById("movieTitle");
				movieTitle = temp.firstChild.nodeValue;
			}
			//Embed with embed tag (other browsers than IE), innerHTML version
			/*
			moviePlaceHolder.innerHTML = '<embed src="'+movieFileName+'" width="640" height="400" autoplay="true" loop="false">';
			moviePlaceHolder.innerHTML += '</embed>';
			moviePlaceHolder.innerHTML += '<br><em>'+movieTitle+', QuickTime movie</em>';
			*/
			//Embed with embed tag (other browsers than IE), DOM version
			var embedTag = document.createElement('embed');
			embedTag.setAttribute('src', movieFileName);
			embedTag.setAttribute('width', otherwidth);
			embedTag.setAttribute('height', otherheight);
			embedTag.setAttribute('autoplay', 'true');
			embedTag.setAttribute('loop', 'false');
			var movieTitleTag = document.createElement('span');
			movieTitleTag.appendChild(document.createTextNode(movieTitle));
			//Add embedTag to page
			moviePlaceHolder.appendChild(embedTag);
			moviePlaceHolder.appendChild(movieTitleTag);
			//Remove content intended for those without javascript
			moviePlaceHolder.removeChild(document.getElementById("movieTitle"));
			moviePlaceHolder.removeChild(document.getElementById("movieScreenShot"));

		}		
	}
}

window.onload = MovieEmbedder.ShowMovie;