	/*** FlashMovie object *****************************************\
	*                                                               *
	* Julian Vallis, 21 Mar 2006                                    *
	*                                                               *
	* When this object is instantiated, it creates a wrapper object *
	* for the Flash movie who's ID is specified, enabling a rich    *
	* set of controls to be used from JavaScript. In addition, it   *
	* also creates the FSCommand handling function which allows     *
	* Flash to call using FSCommand any JS function.                *
	*                                                               *
	* NOTE: Due to Flash Player security settings, this needs to    *
	* work off a web server, and not off a local or network disk.	*
	*  													            *
	* Please see each method for individual documentation           *
	\***************************************************************/

	/* globals
	 *
	 * Due to the time-based nature of Flash, it is necessary to use
	 * a global timer variable and also create an array of each
	 * instance
	 */
	var FlashMovieInterfaces = new Array();
	var FlashMovieInterfaceInterval;

	function FlashMovie(_name)
	{
		// Main instantiation functio - call this to declare
		var f = new FlashMovieInterface(_name);
		FlashMovieInterfaces[FlashMovieInterfaces.length] = f;
		//FlashMovieBrowserFix();
		return f;
	}

	function FlashMovieInterface(_name)
	{
		/* Main instance constructor
		 *lowercase properties are internal, capitalised public
		 * this.Loaded = true|false		checks for movies loaded
		 * 								state
		 */
		this.moviename = _name;

		if (navigator.appName.indexOf('Microsoft') != -1)
			this.movie = eval("document.all['" + this.moviename + "']");
		else
			this.movie = eval('window.document.' + this.moviename);

		if (this.movie != null)
		{
			this.Loaded	   = false;
			this.index	   = FlashMovieInterfaces.length;
			this.PollLoaded();
			this.ImplementFSCommandInterface();
		}
	}

	FlashMovieInterface.prototype.IsPlaying = function()
	{
		/* Checks whether movies is playing
		 * returns true|false
		 *
		 * NOTE: This function only works when the root movie
		 * in the flash file is playing. If not, it will return
		 * the wrong value.
		 */
		return this.movie.IsPlaying();
	}

	FlashMovieInterface.prototype.TotalFrames = function()
	{
		/* Returns the total number of frames in the movie
		 *
		 * By specifying a string of the submovie, the totalframes
		 * of that sub movie will be returned, otherwise by not
		 * specifying, this will only return the root movie
		 */
		if (arguments.length > 0)
			return this.movie.TGetPropertyAsNumber(arguments[0],5);
		else
			return this.movie.TGetPropertyAsNumber("/",5);
	}

	FlashMovieInterface.prototype.PercentLoaded = function()
	{
		/* Returns the percentage loaded. Once loaded, will
		 * always return 100
		 */
		return this.movie.PercentLoaded();
	}

	FlashMovieInterface.prototype.SetVariable = function(_var,_data)
	{
		/* Sets a variable in flash
		 */
		if (this.Loaded)
			this.movie.SetVariable(_var,_data);
	}

	FlashMovieInterface.prototype.GetVariable = function(_var)
	{
		/* Returns a variable in flash
		 */
		if (this.Loaded)
			return this.movie.GetVariable(_var);
		else
			return null;
	}

	FlashMovieInterface.prototype.SetProperty = function(_prop,_val)
	{
		/* Sets a flash property
		 *
		 * By specifying a string of the submovie as the last
		 * argument, the totalframes of that sub movie will be
		 * returned, otherwise by not specifying, this will only
		 * return the root movie
		 */
		if (this.Loaded)
		{
			if (arguments.length > 2)
				this.movie.TSetProperty(arguments[2]+"",_prop+"",_val+"");
			else
				this.movie.TSetProperty("/",_prop+"",_val+"");
		}
	}

	FlashMovieInterface.prototype.GetProperty = function(_prop)
	{
		/* Returns a flash property
		 *
		 * By specifying a string of the submovie as the last
		 * argument, the totalframes of that sub movie will be
		 * returned, otherwise by not specifying, this will only
		 * return the root movie
		 */
		if (this.Loaded)
		{
			if (arguments.length > 1)
				this.movie.GetProperty(_prop,arguments[1]);
			else
				this.movie.GetProperty(_prop,"/");
		}
	}

	FlashMovieInterface.prototype.Play = function()
	{
		/* Plays the movie
		 *
		 * By specifying a string of the submovie as the last
		 * argument, the totalframes of that sub movie will be
		 * returned, otherwise by not specifying, this will only
		 * return the root movie
		 */
		if (this.Loaded)
		{
			if (arguments.length > 0)
				this.movie.TPlay(arguments[0]);
			else
				this.movie.TPlay("/");
		}
	}

	FlashMovieInterface.prototype.Stop = function()
	{
		/* Stops the movie
		 *
		 * By specifying a string of the submovie as the last
		 * argument, the totalframes of that sub movie will be
		 * returned, otherwise by not specifying, this will only
		 * return the root movie
		 */
		if (this.Loaded)
		{
			if (arguments.length > 0)
				this.movie.TStopPlay(arguments[0]);
			else
				this.movie.TStopPlay("/");
		}
	}

	FlashMovieInterface.prototype.Rewind = function()
	{
		/* Rewinds the movie to the first frame
		 *
		 * By specifying a string of the submovie as the last
		 * argument, the totalframes of that sub movie will be
		 * returned, otherwise by not specifying, this will only
		 * return the root movie
		 */
		if (this.Loaded)
		{
			if (arguments.length > 0)
			{
				this.Frame(0,arguments[0]);
			}
			else
			{
				this.Frame(0);
			}
		}
	}

	FlashMovieInterface.prototype.RewindAndStop = function()
	{
		/* Rewinds the movie to the first frame and stops
		 *
		 * By specifying a string of the submovie as the last
		 * argument, the totalframes of that sub movie will be
		 * returned, otherwise by not specifying, this will only
		 * return the root movie
		 */
		if (this.Loaded)
		{
			if (arguments.length > 0)
			{
				this.Stop(arguments[0]);
				this.Frame(0,arguments[0]);
			}
			else
			{
				this.Stop();
				this.Frame(0);
			}
		}
	}

	FlashMovieInterface.prototype.Zoom = function(_factor)
	{
		/* Zooms the flash to specified percentage
		 *
		 * Specifying a positive number zooms in by that many %
		 * Specifying a negative number zooms out by that many %
		 */
		var factor = _factor;
		if (_factor < 0)
			factor=factor*4*-1;
		if (this.Loaded)
			this.movie.Zoom(factor);
	}

	FlashMovieInterface.prototype.ShowAll = function()
	{
		/* Zooms the movie to 100%
		 */
		this.movie.Zoom(0);
	}

	FlashMovieInterface.prototype.Frame = function()
	{
		/* Multimodal function for frame control
		 *
		 * Specifying 'current' as the first argument returns the
		 * current frame in the movie
		 *
		 * Specifying 'last' as the first argument returns the
		 * last frame in the movie
		 *
		 * Specifying a number as the first argument makes the movie
		 * jump to the specified frame
		 *
		 * By specifying a string of the submovie as the last
		 * argument, the totalframes of that sub movie will be
		 * returned, otherwise by not specifying, this will only
		 * return the root movie
		 */
		if (this.Loaded)
		{
			if (arguments.length > 1)
			{
				if (arguments[0] == 'current')
					return this.movie.TGetPropertyAsNumber(arguments[1],4);
				else if (arguments[0] == 'last')
					this.movie.TGotoFrame(arguments[1],this.TotalFrames(arguments[1])-1);
				else
					this.movie.TGotoFrame(arguments[1],arguments[0]);
			}
			else if (arguments.length > 0)
			{
				if (arguments[0] == 'current')
					return this.movie.TGetPropertyAsNumber("/",4);
				else if (arguments[0] == 'last')
					this.movie.TGotoFrame('/',this.TotalFrames()-1);
				else
					this.movie.TGotoFrame('/',arguments[0]);
			}
		}
	}

	FlashMovieInterface.prototype.GotoLabel = function()
	{
		/* Goto a labelled Frame */
		if (this.Loaded)
		{
			if (arguments.length > 1)
				this.movie.TGotoLabel(arguments[1], arguments[0]);
			else
				this.movie.TGotoLabel("/", arguments[0]);
		}
	}

	FlashMovieInterface.prototype.StartFastForward = function()
	{
		/* Starts Fast forwarding in the movie
		 *
		 * Use in conjunction with onkeydown or onmousedown event
		 * handlers
		 *
		 * You must call StopFastForward as well.
		 *
		 * By specifying a string of the submovie as the last
		 * argument, the totalframes of that sub movie will be
		 * returned, otherwise by not specifying, this will only
		 * return the root movie
		 */
		if (this.Loaded)
		{
			if (arguments.length > 0)
			{
				FlashMovieInterfaceInterval = setInterval("FlashMovieInterfaces[" + this.index + "].doFastFoward('" + arguments[0] + "')", 21);
			}
			else
			{
				FlashMovieInterfaceInterval = setInterval("FlashMovieInterfaces[" + this.index + "].doFastFoward()", 21);
			}
		}
	}

	FlashMovieInterface.prototype.StopFastForward = function()
	{
		/* Stops Fast forwarding in the movie
		 *
		 * Use in conjunction with onkeyup or onmouseup event
		 * handlers
		 *
		 * You must call this only after calling StartFastForward
		 */
		clearInterval(FlashMovieInterfaceInterval);
	}

	FlashMovieInterface.prototype.StartRewind = function()
	{
		/* Starts Rewinding the movie
		 *
		 * Use in conjunction with onkeydown or onmousedown event
		 * handlers
		 *
		 * You must call StopRewind as well.
		 *
		 * By specifying a string of the submovie as the last
		 * argument, the totalframes of that sub movie will be
		 * returned, otherwise by not specifying, this will only
		 * return the root movie
		 */
		if (this.Loaded)
		{
			if (arguments.length > 0)
			{
				FlashMovieInterfaceInterval = setInterval("FlashMovieInterfaces[" + this.index + "].doRewind('" + arguments[0] + "')", 21);
			}
			else
			{
				FlashMovieInterfaceInterval = setInterval("FlashMovieInterfaces[" + this.index + "].doRewind()", 21);
			}
		}
	}

	FlashMovieInterface.prototype.StopRewind = function()
	{
		/* Stops rewinding in the movie
		 *
		 * Use in conjunction with onkeyup or onmouseup event
		 * handlers
		 *
		 * You must call this only after calling StartRewind
		 */
		clearInterval(FlashMovieInterfaceInterval);
	}

	FlashMovieInterface.prototype.doFastFoward = function()
	{
		/* Internal function to do the fastforwarding
		 */
		if (arguments.length > 0)
		{
			this.Frame(this.Frame('current',arguments[0])+1,arguments[0]);
		}
		else
		{
			this.Frame(this.Frame('current')+1);
		}
	}

	FlashMovieInterface.prototype.doRewind = function()
	{
		/* Internal function to do the rewinding
		 */
		if (arguments.length > 0)
		{
			this.Frame(this.Frame('current',arguments[0])-2,arguments[0]);
		}
		else
		{
			this.Frame(this.Frame('current')-2);
		}
	}

	FlashMovieInterface.prototype.LoadStatus = function()
	{
		/* internal function to check movie load state
		 */
		if (this.movie.PercentLoaded() == 100)
		{
			clearInterval(FlashMovieInterfaceInterval);
			this.Loaded = true;
			//alert('loaded');
			onflashloaded();
		}
		else
		{
			this.Loaded = false;
		}
		return this.Loaded;
	}

	FlashMovieInterface.prototype.PollLoaded = function()
	{
		/* internal function to poll for movie load state
		 */
		FlashMovieInterfaceInterval = setInterval("FlashMovieInterfaces[" + this.index + "].LoadStatus()", 1);
	}

	FlashMovieInterface.prototype.ImplementFSCommandInterface = function()
	{
		/* internal RPC implementor to create FSCommand interface for Flash
		 *
		 * when calling, you must create a JS function that implements the command
		 * this function simply will call that function directly, and any args passed
		 * will be put in as arguments of the function.
		 */
		var iface = "function " + this.moviename + "_DoFSCommand(command,args) { ";
		iface += " if (args != null) { eval(command + '(' + args + ')'); } ";
		iface += "}"
		eval(iface);
	}

	function FlashMovieBrowserFix()
	{
		objectTags = document.getElementsByTagName("object");

		for (var i = 0; i < objectTags.length; i++)
		{
			objectTags[i].outerHTML = objectTags[i].outerHTML;
		}
	}

	function WriteMovie(_flashfile,_altfile,_id,_w,_h,_bg)
	{
//		var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
//		if(!plugin)
//		{
//			document.write('<img src="' + _altfile + '" alt="BT Softphone - Pick up the easy-to-use low cost phone on your computer" border="0" usemap="#nav-mat">');
//		}
//		else {
			var now = new Date();
			document.write('<div id="flash"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="' + _w + '" height="' + _h + '" id="' + _id + '">');
			document.write('<param name="allowScriptAccess" value="sameDomain" />');
			document.write('<param name="movie" value="' + _flashfile + '" />');
			document.write('<param name="quality" value="high" />');
			var bg = '';
			if (_bg != null)
			{
				if (_bg == 'transparent')
				{
					document.write('<param name="wmode" value="transparent">');
					bg = ' wmode="transparent"';
				}
				else
				{
					document.write('<param name="bgcolor" value="' + _bg + '" />');
					bg = ' bgcolor="' + _bg + '"';
				}
			}
			document.write('<embed src="' + _flashfile + '" quality="high"' + bg + ' width="' + _w + '" height="' + _h + '" name="' + _id + '" swLiveConnect="true" allowscriptaccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
			document.write('</object></div>');
//		}
	}