/*********************************************************************
 *
 * Macromedia Flash Dispatcher -- a scriptable detector for Flash Player
 *
 *
 * copyright (c) 2000 Macromedia, Inc.
 *
 *********************************************************************/


/*
 * MM_FlashInfo() -- construct an object representing Flash Player status
 *
 * Constructor:
 *
 *	new MM_FlashInfo()
 *
 * Properties:
 *
 *	installed		true if player is installed
 *				(undefined if undetectable)
 *
 *	implementation		the form the player takes in this
 *				browser: "ActiveX control" or "Plug-in"
 *
 *	autoInstallable		true if the player can be automatically
 *				installed/updated on this browser/platform
 *
 *	version			player version if installed
 *
 *	revision		revision if implementation is "Plug-in"
 *
 * Methods:
 *
 *	canPlay(contentVersion)	true if installed player is capable of
 *				playing content authored with the
 *				specified version of Flash software
 *
 * Description:
 *
 *	MM_FlashInfo() instantiates an object that contains as much
 *	information about Flash Player--whether it is installed, what
 *	version is installed, and so one--as is possible to collect.
 *
 *	Where Flash Player is implemented as a plug-in and the user's
 *	browser supports plug-in detection, all properties are defined;
 *	this includes Netscape on all platforms and Microsoft Internet
 *	Explorer 5 on the Macintosh.  Where Flash Player is implemented
 *	as an ActiveX control (MSIE on Windows), all properties except
 *	'revision' are defined.
 *
 *	Prior to version 5, Microsoft Internet Explorer on the Macintosh
 *	did not support plug-in detection.  In this case, no properties
 *	are defined, unless the cookie 'MM_FlashDetectedSelf' has been
 *	set, in which case all properties except 'version' and 'revision'
 *	are set.
 *
 *	This object is primarily meant for use by MM_FlashDispatch(), but
 *	may be of use in reporting the player version, etc. to the user.
 */

var MM_FlashControlInstalled;	// is the Flash ActiveX control installed?
var MM_FlashControlVersion;	// ActiveX control version if installed

function MM_FlashInfo()
{
    if (navigator.plugins && navigator.plugins.length > 0)
    {
	this.implementation = "Plug-in";
	this.autoInstallable = false;	// until Netscape SmartUpdate supported

	// Check whether the plug-in is installed:

	if (navigator.plugins["Shockwave Flash"])
	{
	    this.installed = true;

	    // Get the plug-in version and revision:

	    var words =
		navigator.plugins["Shockwave Flash"].description.split(" ");

	    for (var i = 0; i < words.length; ++i)
	    {
		if (isNaN(parseInt(words[i])))
		continue;

		this.version = words[i];
		

		this.revision = parseInt(words[i + 1].substring(1));
	    }
	}
	else
	{
	    this.installed = false;
	}
    }
    else if (MM_FlashControlInstalled != null)
    {
	this.implementation = "ActiveX control";
	this.installed = MM_FlashControlInstalled;
	this.version = MM_FlashControlVersion;
	this.autoInstallable = true;
    }
    else if (MM_FlashDetectedSelf())
    {
	this.installed = true;
	this.implementation = "Plug-in";
	this.autoInstallable = false;
    }

    this.canPlay = MM_FlashCanPlay;
}

/*
 * MM_FlashCanPlay() -- check whether installed Flash Player can play content
 *
 * Synopsis:
 *
 *	MM_FlashCanPlay(contentVersion, requireLatestRevision)
 *
 *	Arguments:
 *
 *	    contentVersion		version of Flash software used to
 *					author content
 *
 *	    requireLatestRevision	Boolean indicating whether latest
 *					revision of plug-in should be required
 *
 *	Returns:
 *
 *	    true if the installed player can play the indicated content;
 *	    false otherwise.
 *
 * Description:
 *
 *	This function is not intended to be called directly, only
 *	as an instance method of MM_FlashInfo.
 */

function MM_FlashCanPlay(contentVersion, requireLatestRevision)
{
    var canPlay;

    if (this.version)
    {
	canPlay = (parseInt(contentVersion) <= this.version);

	if (requireLatestRevision)
	{
	    if (this.revision &&
		this.revision < MM_FlashLatestPluginRevision(this.version))
	    {
		canPlay = false;
	    }
	}
    }
    else
    {
	canPlay = MM_FlashDetectedSelf();
    }

    return canPlay;
}


/*
 * MM_FlashDetectedSelf() -- recall whether Flash Player has detected itself
 *
 * Synopsis:
 *
 *	MM_FlashDetectedSelf()
 *
 *	Returns:
 *
 *	    true if a cookie signifying that Flash Player has detected itself
 *	    is set; false otherwise.
 *
 * Description:
 *
 *	This function is only meant to be called internally.
 */

function MM_FlashDetectedSelf()
{
    return (document.cookie.indexOf("MM_FlashDetectedSelf") != -1);
}


function flash_detect(version)
{
    var player = new MM_FlashInfo();

    if (player.installed == null)
    {
		return false;
	} else {
		if (player.canPlay(version,0))
			return true;
		else
			return false;
	}	
}

function show_flash_or_image(version, flash, image, width, height)
{
	if (flash_detect(version)) 
	{
	//document.open();
	document.write("<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" WIDTH="+width+" HEIGHT="+height+">");
	document.write("<PARAM NAME=movie VALUE=\""+flash+"\"> <PARAM NAME=quality VALUE=high> <PARAM NAME=bgcolor VALUE=#FFFFFF>");
	document.write("<EMBED src=\""+flash+"\" quality=high bgcolor=#FFFFFF  WIDTH="+width+" HEIGHT="+height+" TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\"></EMBED>");
	document.write("</OBJECT>");
	//document.close();
	}
	else
	{
	//		document.open();
			document.write("<img src=\""+image+"\" border=0 width="+width+" height="+height+" alt=\"\">");
	//		document.close();
	}
}
