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
	}
}

// Function that extracts variables from arguments passed to page
function parseArgs() {
	var myLocation = location.href;
	
	if (myLocation.indexOf('?') != -1) {
		var myArgString = unescape(myLocation.substring(myLocation.indexOf('?') + 1, myLocation.length));
		if (myArgString.indexOf('&') != -1) {
			var myArgs = myArgString.split('&');
			for (argLoop = 0; argLoop < myArgs.length; argLoop++) {
				evalArg(myArgs[argLoop]);
			}
		} else {
			evalArg(myArgString);
		}
	}
}

// Evaluates string of the form "key=value"
function evalArg(argString) {
	var keyAndValue = argString.split('=');
	if (isNaN(keyAndValue[1])) {
		eval(keyAndValue[0] + '="' + keyAndValue[1] + '"');
	} else {
		eval(argString);
	}
}

// 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 + '>');
	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=bgcolor VALUE="' + bgcolor + '">');
	document.writeln('				<PARAM NAME=menu VALUE=false>');
	document.writeln('				<EMBED NAME=myFlashMovie');
	document.writeln('							 SRC="' + filename + '.swf' + argString + '"');
	document.writeln('							 WIDTH=' + width + ' HEIGHT=' + height);
	document.writeln('							 LOOP=false');
	document.writeln('							 QUALITY=high');
	document.writeln('							 BGCOLOR=' + bgcolor);
	document.writeln('							 MENU=false');
	document.writeln('							 SWLIVECONNECT=true');
	document.writeln(' 							 TYPE="application/x-shockwave-flash"');
	document.writeln(' 							 PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">');
	document.writeln('				</EMBED>');
	document.writeln('</OBJECT>');
}