/*
 * flash-detection.js
 * by Keith Gaughan <keith@digital-crew.com>
 *
 * Nice, clean, cross-platform, sane Macromedia Flash detection and inclusion.
 *
 * Copyright (c) Digital Crew Ltd., 2004.
 * All Rights Reserved.
 *
 * TODO: Code to replace given elements in a page with Flash movies.
 */

/*
 * Detects flash in a portable, cross-platform manner, returning a simple
 * boolean to say whether it exists or not.
 *
 * Might change this in the future to return a version number, so don't test
 * against true or false.
 */
function IsFlashAvailable()
{
	// Mozilla, NS3+, Opera3+, IE5+ Mac.
	if (navigator.plugins && navigator.plugins.length > 0)
	{
		if (navigator.plugins["Shockwave Flash"])
			return true;
	}
	else if (navigator.mimeTypes && navigator.mimeTypes.length)
	{
		var x = navigator.mimeTypes["application/x-shockwave-flash"];
		return x && x.enabledPlugin;
	}

	// IE.
	if (typeof ActiveXObject != "undefined")
		if (new ActiveXObject("ShockwaveFlash.ShockwaveFlash"))
			return true;

	// Fill in for more browsers here, or if there's some other method that
	// works, use it.

	// Can't detect
	return false;
}

/*
 * Checks to see if the given Flash movie can be shown, and if so writes out
 * the required HTML.
 *
 * Note: find some better way of doing this: document.write feels kinda nasty.
 */
function IncludeFlashMovie(src, w, h)
{
	if (IsFlashAvailable())
	{
		document.write("<object classid=\"clsid:D27CDB6E-AE6D-11CF-96B8-444553540000\" " +
			"width=\"" + w + "\" height=\"" + h +
			"\" codebase=\"http://active.macromedia.com/flash5/cabs/swflash.cab#version=5,0,0,0\">" +
			"<param name=\"movie\" value=\"" + src + "\">" +
			"<param name=\"play\" value=\"true\">" +
			"<param name=\"loop\" value=\"false\">" +
			"<param name=\"quality\" value=\"high\">" +
			"<embed src=\"" + src + "\" width=\"" + w +
			"\" height=\"" + h + "\" loop=\"false\" quality=\"high\" " +
			"type=\"application/x-shockwave-flash\"" +
			" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"" +
			" swliveconnect=\"true\"></embed></object>");

		return true;
	}

	return false;
}
