var	agent = navigator.userAgent.toLowerCase();

// plug-in detection
function hasPlugin(pluginName, pluginVersion) {	
	if (agent.indexOf('msie') != -1 && agent.indexOf('win') != -1) {
		//Internet Explorer on Windows
		switch(pluginName) {
		case 'RealPlayer':
			return doRealActiveXCheck();
			break;
		case 'Shockwave Flash':
			if (pluginVersion == null) {
				return true;
			} else {
				return doFlashActiveXCheck(pluginVersion);
			}
			break;
		default:
			return true; //IE on Windows will auto download certain plug-ins
		}
	} else if (navigator.plugins) {
		for (var pluginLoop = 0; pluginLoop < navigator.plugins.length; pluginLoop++) {
			if (navigator.plugins[pluginLoop].name.indexOf(pluginName) != -1) {
				if (pluginName == 'Shockwave Flash' && pluginVersion != null) {
					//Flash version check required
					var words = navigator.plugins[pluginLoop].description.split(' ');
	    		for (var wordLoop = 0; wordLoop < words.length; ++wordLoop) {
						if (isNaN(parseInt(words[wordLoop]))) continue;
						var browserPluginVersion = words[wordLoop];
	    		}
					return browserPluginVersion >= pluginVersion;
				} else {
					return true;
				}
			}
		}
		return false;
	} else {
		return true; //browser doesn't have plug-in object - may still support plug-ins
	}
}

// Embeds a real player movie of the given name and size
function playReal(filename, width, height) {
	document.writeln('<OBJECT id=myRealMovie classid=clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA');
	document.writeln('				width=' + width + ' height=' + height + '>');
	document.writeln('				<PARAM NAME="SRC" VALUE="' + filename + '.ram">');
	document.writeln('				<PARAM NAME="CONSOLE" VALUE="_master">');
	document.writeln('				<PARAM NAME="CONTROLS" VALUE="ImageWindow">');
	document.writeln('				<PARAM NAME="BACKGROUNDCOLOR" VALUE="#000000">');
	document.writeln('				<PARAM NAME="AUTOSTART" VALUE="true">');
	document.writeln('				<PARAM NAME="LOOP" VALUE="false">');
	document.writeln('				<PARAM NAME="NOLOGO" VALUE="true">');
	document.writeln('      	<EMBED NAME=myRealMovie');
	document.writeln('							 SRC="' + filename + '.ram"');
	document.writeln('							 WIDTH=' + width + ' HEIGHT=' + height);
	document.writeln('							 CONSOLE=_master');
	document.writeln('							 CONTROLS=ImageWindow');
	document.writeln('							 BACKGROUNDCOLOR=black');
	document.writeln('							 AUTOSTART=true');
	document.writeln('							 LOOP=false');
	document.writeln('							 NOLOGO=true');
	document.writeln('							 NOJAVA=false');
	document.writeln('							 TYPE="audio/x-pn-realaudio-plugin"');
	document.writeln('							 PLUGINSPAGE="http://www.real.com/player/"');
	document.writeln('				</EMBED>');
	document.writeln('</OBJECT>');
}

// Embeds a QuickTime movie of the given name and size
function playQuickTime(filename, width, height) {
	document.writeln('<OBJECT CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"');
	document.writeln('				CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab"');
	document.writeln(' 				WIDTH="' + width + '" HEIGHT="' + height + '">');
	document.writeln('				<PARAM NAME="SRC" VALUE="' + filename + '.mov">');
	document.writeln('				<PARAM NAME="AUTOPLAY" VALUE="true">');
	document.writeln('				<PARAM NAME="CONTROLLER" VALUE="true">');
	document.writeln('				<PARAM NAME="KIOSKMODE" VALUE="true">');
	document.writeln('				<PARAM NAME="BGCOLOR" VALUE="#000000">');
	document.writeln('				<EMBED SRC="' + filename + '.mov"');
	document.writeln('							 WIDTH="' + width + '" HEIGHT="' + height + '"');
	document.writeln('							 AUTOPLAY="true"');
	document.writeln('							 CONTROLLER="true"');
	document.writeln('							 KIOSKMODE="true"');
	document.writeln('							 BGCOLOR="#000000"');
	document.writeln('							 PLUGINSPAGE="http://www.apple.com/quicktime/download/">');
	document.writeln('				</EMBED>');
	document.writeln('</OBJECT>');
}

// Embeds a flash movie of the given name and size and passes args to it
function playFlash(filename, width, height, bgcolor, args) {

	//evaluate each argument
	var argString = new String();
	for (arg in args) {
		var pair = arg + '=' + eval('args.' + arg);
		argString += (argString == '') ? '?' + pair : '&' + pair;
	}
	
	document.writeln('<OBJECT id=myFlashMovie classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
	document.writeln('				codebase="http://active.macromedia.com/flash/cabs/swflash.cab#version=6,0,0,0"');
	document.writeln('	 			width=' + width + ' height=' + height + ' id="myFlashMovie">');
	document.writeln('				<PARAM NAME=movie VALUE="' + filename + '.swf' + argString + '">');
	document.writeln('				<PARAM NAME=loop VALUE=false>');
	document.writeln('				<PARAM NAME=quality VALUE=high>');
	document.writeln('				<PARAM NAME=salign VALUE=LT>');
	document.writeln('				<PARAM NAME=bgcolor VALUE="' + bgcolor + '">');
	document.writeln('				<EMBED NAME=myFlashMovie');
	document.writeln('							 SRC="' + filename + '.swf' + argString + '"');
	document.writeln('							 WIDTH=' + width + ' HEIGHT=' + height + ' NAME="myFlashMovie"');
	document.writeln('							 LOOP=false');
	document.writeln('							 QUALITY=high');
	document.writeln('							 SALIGN=LT');
	document.writeln('							 BGCOLOR=' + bgcolor);
	document.writeln('							 SWLIVECONNECT=false');
	document.writeln(' 							 TYPE="application/x-shockwave-flash"');
	document.writeln(' 							 PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">');
	document.writeln('				</EMBED>');
	document.writeln('</OBJECT>');
}