﻿/*
######################################################################################################
Functions to handle embedding of flash player object used for homepage banner
-------------------------------------------------------------------------------
The functions provide an interface to swfobject.embedSWF, adding some error trapping 
and DOM Load control. 

The SWFObject EMBED dynamically overwrites a container element with an OBJECT  reference to the 
SWF file. If the container element does not exist the script goes no further

If the container element exists but the creation of the OBJECT fails for any reason, the script 
rolls back the change and restores the existing content

All variables are passed to customSWFEmbed, some are then passed to SWFObject:

Required for customSWFEmbed
---------------------------
* swfBaseURL (String, required) - Specifies base string to use to build URLs for 
		SWF Object and ExpressInstall SWF location.	

Required for SWFObject
----------------------
* swfURL (String, required) - specifies the URL of your SWF
* swfReplacementContainer (String, required) specifies the id of the HTML element 
	(containing your alternative content) you would like to have replaced by your Flash content
* swfWidth (String, required) specifies the width of your SWF
* swfHeight (String, required) specifies the height of your SWF   
* flashVer (String, required) specifies the Flash player version your SWF is published for 
	(format is: "major.minor.release")

Optional for SWFObject
----------------------
* expressInstallURL (String, optional) specifies the URL of your express install SWF and 
  activates Adobe express install 
	[ http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=6a253b75 ]. 
	Please note that express install will only fire once (the first time that it is invoked), 
	that it is only supported by Flash Player 6.0.65 or higher on Win or Mac platforms, 
	and that it requires a minimal SWF size of 310x137px.
* flashvars (Object, optional) specifies your flashvars with name:value pairs
* params (Object, optional) specifies your nested object element params with name:value pairs
* attributes (Object, optional) specifies your object's attributes with name:value pairs 

Further information about SWFObject - http://code.google.com/p/swfobject/wiki/documentation
######################################################################################################
*/

//global vars for SWFObject / Flash banner

//apend timestamp to filename
	var swfURL = "http://web.anglia.ac.uk/media/banner_rotator/front_banner_container.swf?1268746645";
	var swfReplacementContainer= "media-banner";
	var flashInfoContainer = "browser-check-flash-information";
	var noScriptContainer = "media-banner-noscript-content";

function customSWFEmbed(swfURL,swfContainer,swfHeight,swfWidth,flashVer,expressInstallURL,flashvars, params, attributes)		
{		
	/*
	Identify the media container element i.e. the container that get replaced by the flash 
	player component - SWFobject dynamic method
	*/
	var containerObj = document.getElementById(swfContainer);
	//if the target container doesn't exist then go no further

	if(containerObj)
	{
		/*
		Get the existing HTML content of the target container's noscript element 		
		if the user doesn't have a supported version of flash then display this content 
		i.e. static image from QC
		*/		
		var fallbackObj = document.getElementById(noScriptContainer);
		var fallbackHTML = fallbackObj.innerHTML;
	
		//check that user has a supported version
		if (swfobject.hasFlashPlayerVersion(flashVer))
		{
			//carry out swfobject.embedSWF	
			swfobject.embedSWF(swfURL,swfContainer,swfHeight,swfWidth,flashVer,expressInstallURL, flashvars, params, attributes);
		}
		else
		{
			//get the container that will hold the flash warning
			var flashInfocontainerObj = document.getElementById(flashInfoContainer);
		
			//create a message to instruct user that page requires specific version of Flash or greater
			var flashPlayerMessage = "The video content used on this site requires Flash version 7.0.0 or greater";

			//if the message DIV exists then write to it, othwerwise use an alert
			if(flashInfocontainerObj)
			{
				flashInfocontainerObj.style.display = "block";
		    flashInfocontainerObj.innerHTML = flashPlayerMessage;
			}
			else
			{
				alert(flashPlayerMessage);
			}
			//insert static content HTML into container
			containerObj.innerHTML = fallbackHTML;
		}
	}
}	

function doEmbed()
{
	//set variables
	var swfWidth= "466";
	var swfHeight= "245";
	var flashVer= "7.0.0";
	var expressInstallURL=null;
	var flashvars= false;
	var params = 
	{
		allowScriptAccess: "always",
		allowFullScreen: "false",
		scale: "noorder",
		quality: "best",
		bgcolor: "#ffffff",
		base: "."
	};
	var attributes = false;

	customSWFEmbed(swfURL,swfReplacementContainer,swfWidth,swfHeight,flashVer,expressInstallURL,flashvars, params, attributes)
}
//add DOM on load event to call custom embed function	
swfobject.addDomLoadEvent(doEmbed);