
var MM_FlashSnifferURL = "detect.swf";

var MM_latestPluginRevision = new Object();

MM_latestPluginRevision["6.0"] = new Object();
MM_latestPluginRevision["5.0"] = new Object();
MM_latestPluginRevision["4.0"] = new Object();
MM_latestPluginRevision["3.0"] = new Object();
MM_latestPluginRevision["2.0"] = new Object();

MM_latestPluginRevision["6.0"]["Windows"] = 29;
MM_latestPluginRevision["6.0"]["Macintosh"] = 29;
MM_latestPluginRevision["5.0"]["Windows"] = 42;
MM_latestPluginRevision["5.0"]["Macintosh"] = 41;
MM_latestPluginRevision["4.0"]["Windows"] = 28;
MM_latestPluginRevision["4.0"]["Macintosh"] = 27;
MM_latestPluginRevision["4.0"]["Unix"] = 12;
MM_latestPluginRevision["3.0"]["Windows"] = 10;
MM_latestPluginRevision["3.0"]["Macintosh"] = 10;
MM_latestPluginRevision["2.0"]["Windows"] = 11;
MM_latestPluginRevision["2.0"]["Macintosh"] = 11;

var MM_FlashControlInstalled;
var MM_FlashControlVersion;

function MM_FlashInfo() {
	
	if(navigator.plugins && navigator.plugins.length > 0) {
	    	
		this.implementation = "Plug-in";
		this.autoInstallable = false;
		
		if(navigator.plugins["Shockwave Flash"]) {
			
			this.installed = true;
			
			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;
}

var MM_FlashPluginsPage = "http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash";

function MM_FlashDispatch(contentURL, contentVersion, requireLatestRevision, upgradeURL, install, installURL, altURL, overridePluginsPage, disableAutoInstall) {
	
	var player;
	var sniffer;
	
	if(disableAutoInstall == null) {
		
		alert("ERROR: MM_FlashDispatch() called with too few arguments.");
		return;
	}
	if(overridePluginsPage && installURL.substring(0, 7) != "http://") {
		
		alert("ERROR: MM_FlashDispatch() called with relative URL" + " for PLUGINSPAGE (" + installURL + ")");
		return;
	}
	player = new MM_FlashInfo();
	if(player.installed == null) {
		
		document.open();
		document.write("<HTML>\r\n");
		document.write("\t<HEAD>\r\n");
		document.write("\t\t\r\n");
		document.write("\t\t<TITLE>&nbsp;</TITLE>\r\n");
		document.write("\t</HEAD>\r\n");
		document.write("\t<BODY BGCOLOR=\"#A9A9A9\">\r\n");
		document.write("\t\t\r\n");
		sniffer = "\t\t<EMBED HIDDEN=\"true\" TYPE=\"application/x-shockwave-flash\" WIDTH=\"18\" HEIGHT=\"18\"";
		sniffer += " SRC=\"" + MM_FlashSnifferURL + "?contentURL=" + contentURL + "&contentVersion=" + contentVersion;
		sniffer += "&latestRevision=" + MM_FlashLatestPluginRevision(contentVersion) + "&upgradeURL=" +  upgradeURL + "&requireLatestRevision=" + requireLatestRevision + "\"";
		sniffer += " LOOP=\"false\" MENU=\"false\"" + " PLUGINSPAGE=\"" + (overridePluginsPage ? installURL : MM_FlashPluginsPage) + "\"" + ">";
		sniffer += "</EMBED>\r\n";
		document.write(sniffer);
		document.write("\t</BODY>\r\n");
		document.write("</HTML>\r\n");
		document.close();
	}
	else if(player.installed) {
		
	if (player.canPlay(contentVersion, requireLatestRevision))
	{
	    location = contentURL;
	}
	else
	{
	if (disableAutoInstall)
	{
	location = upgradeURL;
	}else
	{
	    location = player.autoInstallable ? contentURL : upgradeURL;
	}
	}
    }
    else if (install)
    {
	if (disableAutoInstall){
	location = installURL;
	}
	else{
	location = player.autoInstallable ? contentURL : installURL;
	}
    }
    else
    {
	location = altURL;
    }
}


/*
 * MM_FlashRememberIfDetectedSelf() -- record that Flash Player detected itself
 *
 * Synopsis:
 *
 *	MM_FlashRememberIfDetectedSelf()
 *	MM_FlashRememberIfDetectedSelf(count)
 *	MM_FlashRememberIfDetectedSelf(count, units)
 *
 *	Arguments:
 *
 *	    count		length of time in units before re-checking
 *				whether content can be played (default: 60)
 *
 *	    units		unit(s) of time to count: "minute(s)," "hour(s)"
 * 				or "day(s)" (default: "days")
 *
 *
 * Description:
 *
 *	This function conditionally sets a cookie signifying that
 *	the current document was referred via the Dispatcher using
 *	Flash Player self-detection.  It is intended to spare the user
 *	whose browser does not support script-based detection from the
 *	process of Flash Player self-detection on each visit.
 *	
 *	The cookie persists for 60 days, or for the amount of time
 *	specified by the 'count' and 'units' parameters.
 *
 *	If cookies are not being accepted, this function is a no-op;
 *	the Dispatcher will simply attempt Flash Player self-detection
 *	on subsequent visits.
 *
 *	This function must be called from a script embedded in the
 *	document referenced by the 'contentURL' argument to
 *	MM_FlashDispatch().
 *
 */

function MM_FlashRememberIfDetectedSelf(count, units)
{
    // the sniffer appends an empty search string to the URL
    // to indicate that it is the referrer

    if (document.location.search.indexOf("?") != -1)
    {
	if (!count) count = 60;
	if (!units) units = "days";

	var msecs = new Object();

	msecs.minute = msecs.minutes = 60000;
	msecs.hour = msecs.hours = 60 * msecs.minute;
	msecs.day = msecs.days = 24 * msecs.hour;

	var expires = new Date();

	expires.setTime(expires.getTime() + count * msecs[units]);

	document.cookie =
	    'MM_FlashDetectedSelf=true ; expires=' + expires.toGMTString();
	}
}

function MM_FlashDemur(count, units) {
	
	if(!count) count = 60;
	if(!units) units = "days";
	
	var msecs = new Object();
	
	msecs.minute = msecs.minutes = 60000;
	msecs.hour = msecs.hours = 60 * msecs.minute;
	msecs.day = msecs.days = 24 * msecs.hour;
	
	var expires = new Date();
	
	expires.setTime(expires.getTime() + count * msecs[units]);
	document.cookie = 'MM_FlashUserDemurred=true ; expires=' + expires.toGMTString();
	if(!MM_FlashUserDemurred()) {
		
		alert("Your browser must accept cookies in order to save this information. Try changing your preferences.");
		return false;
	}
	else {
		
		return true;
	}
}

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

/*********************************************************************
 * THE FOLLOWING FUNCTIONS ARE NOT PUBLIC.  DO NOT CALL THEM DIRECTLY.
 *********************************************************************/

/*
 * MM_FlashLatestPluginRevision() -- look up latest Flash Player plug-in
 *				     revision for this platform
 *
 * Synopsis:
 *
 *	MM_FlashLatestPluginRevision(playerVersion)
 *
 *	Arguments:
 *
 *	    playerVersion	plug-in version to look up revision of
 *
 *	Returns:
 *
 *	    The latest available revision of the specified version of
 *	    the Flash Player plug-in on this platform, as an integer;
 *	    undefined for versions before 2.0.
 *
 * Description:
 *
 *	This look-up function is only intended to be called internally.
 */

function MM_FlashLatestPluginRevision(playerVersion)
{
    var latestRevision;
    var platform;

    if (navigator.appVersion.indexOf("Win") != -1)
	platform = "Windows";
    else if (navigator.appVersion.indexOf("Macintosh") != -1)
	platform = "Macintosh";
    else if (navigator.appVersion.indexOf("X11") != -1)
	platform = "Unix";

    latestRevision = MM_latestPluginRevision[playerVersion][platform];

    return latestRevision;
}


/*
 * 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);
}
