/* INSTRUCTIONS:
Define the following variables in your html page before including this script:
	var moviename: string, the name of the swf file to load
	var moviewidth: integer, width of movie object
	var movieheight: integer, height of the movie object

These variables are optional.  If not set before including this script, their default values will be set:
	var swLiveConnect: must be either "true" or "false".  Defaults to "true"
	var moviebgcolor: string, the background color for the movie.  Defaults to "#ffffff"
	var moviequality: string, the quality of the movie.  Defaults to "autohigh"
	var altFlashImg: string, the alternate image to be displayed.
	
Insert this script directly into your HTML with the line <script language="JavaScript1.2" src="flash.js"></script>
wherever you want the flash movie to be displayed.
*/

var _swLiveConnect;
var _moviebgcolor;
var _moviequality;

if (typeof(swLiveConnect) == "undefined") _swLiveConnect = "true";
else _swLiveConnect = swLiveConnect;

if (typeof(moviebgcolor) == "undefined") _moviebgcolor = "#ffffff";
else _moviebgcolor = moviebgcolor;

if (typeof(moviequality) == "undefined") _moviequality = "autohigh";
else _moviequality = moviequality;

if (typeof(moviename) == "undefined" || typeof(moviewidth) == "undefined" || typeof(movieheight) == "undefined") {
	var alertstring = "The following variable names must be defined in your page before 'flash.js' can be included.\n";
	if (typeof(moviename) == "undefined") alertstring += " - moviename\n";
	if (typeof(moviewidth) == "undefined") alertstring += " - moviewidth\n";
	if (typeof(movieheight) == "undefined") alertstring += " - movieheight\n";
	alert(alertstring);
}

var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
// Handle all the the FSCommand messages in a FutureSplash movie

function NAMEOFMOVIE_DoFSCommand(command, args) {
	var flashObj = InternetExplorer ? NAMEOFMOVIE : document.flashset;
	//to control the movie itself via FS
	//do something like
	//  flashObj.StopPlay();
	
	//to transfer the FS command to a JS function
	//just check the command and pass it on...
	// if (command == 'what') {doJS(args)}

}

// Hook for Internet Explorer to understand the JS call from FS
if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0) {
	document.write('<SCRIPT LANGUAGE=VBScript\> \n');
	document.write('on error resume next \n');
	document.write('Sub NAMEOFMOVIE_FSCommand(ByVal command, ByVal args)\n');
	document.write('  call NAMEOFMOVIE_DoFSCommand(command, args)\n');
	document.write('end sub\n');
	document.write('</SCRIPT\> \n');
}

//CHECKING STUFF HERE.......
if (navigator.appName.indexOf("Netscape") != -1 || navigator.platform.indexOf("Mac") != -1) {
//Do Navigator Stuff to check for flash
	var ShockMode = 0;
	var OldVersionOfPlugin = 0;
	if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"] && navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin) {
		if (navigator.plugins && navigator.plugins["Shockwave Flash"])
			ShockMode = 1;
	}
	if (navigator.appName.indexOf("Netscape") == -1 && navigator.platform.indexOf("Mac") != -1) {
		ShockMode = 1;
	}

} else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0) {
//do IE stuff to check for flash
	document.write("<SCRIPT LANGUAGE=VBScript\> \n");
	document.write("on error resume next \n");
	document.write("ShockMode = (IsObject(CreateObject(\"ShockwaveFlash.ShockwaveFlash.3\")))\n");
	document.write("<\/SCRIPT\> \n");
}

//setup your commands for what to do
if (ShockMode) {
	//write out the embeds, etc for a flash movie
	flashWrite();
} else {
	//do a little more checking
	//or do a dynamic install with NS4
	getFlash();
}


//to get Netscape to download and install flash behind the scenes 
//do this

function checkForShockwave()
{
	navigator.plugins.refresh();
	if ( navigator.plugins["Shockwave Flash"] ){ 
		//code goes here that tells the browser what to do once flash has
		//downloaded and installed
	} else {
		setTimeout( "checkForShockwave()", 1000 );
	}
}

function getFlash() {
//check for live update capability
if (navigator.appName && navigator.appName.indexOf("Netscape") != - 1 && navigator.appVersion.indexOf("4.") != - 1
&& navigator.javaEnabled() && netscape.softupdate.Trigger.UpdateEnabled() && document.cookie.indexOf("StartedShockwaveInstall") == -1) {
	var jarPath = new String("");
	if (navigator.platform.indexOf("Win32") >= 0 )
		jarPath = "http://download.macromedia.com/pub/shockwave/jars/english/silentflash32.jar"
	else if (navigator.platform.indexOf("Win16") >= 0 )
		jarPath = "http://download.macromedia.com/pub/shockwave/jars/english/silentflash16.jar"
	else if (navigator.platform.indexOf("MacPPC") >= 0 )
		jarPath = "http://download.macromedia.com/pub/shockwave/jars/english/silentflashppc.jar"
	if (jarPath.length) {
		netscape.softupdate.Trigger.StartSoftwareUpdate (jarPath, netscape.softupdate.Trigger.FORCE_MODE);
		document.cookie='StartedShockwaveInstall;path=/;'
		setTimeout("checkForShockwave()", 1000);
	}
} else {
	//force browsers that do not have live update and do not have flash installed to write the image.
	if (typeof(altFlashImg) != "undefined") {
		document.write("<IMG SRC='" + altFlashImg + "'>");
	}
	else {
		document.write("<IMG SRC='images/cp.gif' WIDTH='" + moviewidth + "' HEIGHT='" + movieheight + "' BORDER='0'>");
	}
} 
}

function flashWrite() {
	if (typeof(moviename) == "undefined" || typeof(moviewidth) == "undefined" || typeof(movieheight) == "undefined") {
		document.write("The flash movie could not be loaded because required variable names were not defined prior to including flash.js");
	} else {
		document.write("<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://active.macromedia.com/flash2/cabs/swflash.cab#version=5,0,0,0' ID='" + moviename + "' WIDTH='" + moviewidth + "' HEIGHT='" + movieheight + "'>");
		document.write("<PARAM NAME='movie' VALUE='" + moviename + "'>");
		document.write("<PARAM NAME='quality' VALUE=" + _moviequality + ">");
		document.write("<PARAM NAME='bgcolor' VALUE='" + _moviebgcolor + "'>");
		document.write("<EMBED SRC='" + moviename + "' NAME='" + moviename + "' swLiveConnect=" + _swLiveConnect + " WIDTH=" + moviewidth + " HEIGHT=" + movieheight + " QUALITY=" + _moviequality + " BGCOLOR=" + _moviebgcolor + " TYPE='application/x-shockwave-flash' PLUGINSPAGE='http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash'>");
		document.write("</EMBED></OBJECT>");
	}
}