//
//	Function to create an <object> tag
//
function objectify(type, width, height, url, autoplay, controller)
{
	var d = document.getElementById(type);
	if (d) {
		if (type == 'flaudio' || type == 'flash') {
			if (get_flash_version() < 8) {
				type = 'qtaudio';
				url = controller;
				controller = "true";
			}
			else {
				e = '<embed width="' + width + '" height="' + height + '" src="' + url + '" play="' + autoplay + '" loop="false" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" />\n';
				s =	'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" id="' + type + '" width="' + width + '" height="' + height + '">\n' +
						'<param name="src" value="' + url + '" />\n' +
						'<param name="width" value="' + width + '" />\n' +
						'<param name="height" value="' + height + '" />\n' +
						'<param name="play" value="' + autoplay + '" />\n' +
						'<param name="loop" value="false" />\n' +
						'<param name="quality" value="high" />\n' +
						 e +
					'</object>\n';
				d.innerHTML = s; // + '<p>Oyez Audio Player (' + type + ': ' + get_flash_version() + ')</p>';
				return;
			}
		}
		if (type == 'flvideo') {
			if (get_flash_version() < 8) {
				type = 'qtvideo';
				url = controller;
				controller = "true";
			}
			else {
				e = '<embed width="' + width + '" height="' + height + '" src="/flash/oyezplayer.swf?oyezurl=' + url + '" play="' + autoplay + '" loop="false" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" />\n';
				s =	'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://active.macromedia.com/flash7/cabs/swflash.cab#version=9,0,0,0" id="' + type + '" width="' + width + '" height="' + height + '">\n' +
						'<param name="src" value="/flash/oyezplayer.swf?oyezurl=' + url + '" />\n' +
						'<param name="width" value="' + width + '" />\n' +
						'<param name="height" value="' + height + '" />\n' +
						'<param name="play" value="' + autoplay + '" />\n' +
						'<param name="loop" value="false" />\n' +
						'<param name="quality" value="high" />\n' +
						 e +
					'</object>\n';
				d.innerHTML = s; // + '<p>Oyez Video Player (' + type + ': ' + get_flash_version() + ')</p>';
				return;
			}
		}
		else
		if (type == 'qtaudio' || type == 'qtvideo' || type == 'qtvr') {
			if (type == 'qtaudio' || type == 'qtvideo')
				e = '<embed width="' + width + '" height="' + height + '" src="' + url + '" autoplay="' + autoplay + '" controller="' + controller + '" pluginspage="http://www.apple.com/quicktime/download/" />\n';
			else
				e = '<embed width="' + width + '" height="' + height + '" src="' + url + '" autoplay="' + autoplay + '" controller="' + controller + '" loop="false" cache="true" scale="aspect" fov="50" style="border: thin solid black;" pluginspage="http://www.apple.com/quicktime/download/" />\n';
			s =	'<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" id="' + type + '" width="' + width + '" height="' + height + '">\n' +
					'<param name="src" value="' + url + '" />\n' +
					'<param name="width" value="' + width + '" />\n' +
					'<param name="height" value="' + height + '" />\n' +
					'<param name="autoplay" value="' + autoplay + '" />\n' +
					'<param name="controller" value="' + controller + '" />\n' +
					 e +
				'</object>\n';
			d.innerHTML = s; // + '<p>Oyez Media Player (' + type + ')</p>';
		}
		else {
			d.innerHTML = "Unrecognized media type: " + type;
		}
	}
}

function objectify_blob(type, blob)
{
	var d = document.getElementById(type);
	if (d) {
		d.innerHTML = blob;
	}
}

//
//	The following function was adapted from:
//
//	SWFObject v1.5: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
//
//	SWFObject is (c) 2007 Geoff Stearns and is released under the MIT License:
//	http://www.opensource.org/licenses/mit-license.php
//
function get_flash_version()
{
	var arrVersion = [0,0,0];	// major, minor, rev
	if (navigator.plugins && navigator.mimeTypes.length) {
		var x = navigator.plugins["Shockwave Flash"];
		if (x && x.description) {
			arrVersion = x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split(".");
		}
	}
	else if (navigator.userAgent && navigator.userAgent.indexOf("Windows CE") >= 0) { // if Windows CE
		var axo = 1;
		var counter = 3;
		while (axo) {
			try {
				counter++;
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+ counter);
				arrVersion = [counter,0,0];
			} catch (e) {
				axo = null;
			}
		}
	}
	else { // Win IE (non mobile)
		// do minor version lookup in IE, but avoid fp6 crashing issues
		// see http://blog.deconcept.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
		try {
			var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
		} catch(e) {
			try {
				var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
				arrVersion = [6,0,21];
				axo.AllowScriptAccess = "always"; // error if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
			} catch(e) {
				if (arrVersion[0] == 6) {
					return arrVersion[0];
				}
			}
			try {
				axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			} catch(e) {}
		}
		if (axo != null) {
			arrVersion = axo.GetVariable("$version").split(" ")[1].split(",");
		}
	}
	return arrVersion[0] != null? parseInt(arrVersion[0]) : 0;
}

