﻿////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// JScript File encapsulates the functionality for embedding flash movies on pages and playing them
// See documentation for details
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$(document).ready(function()
{			
	var container = null;			// Container holding the flash player object
	var containerID = "flashMov";	// ID of the container where flash player will run
	var containerWidth = "300";		// Width of the container
	var containerHeight = "120";	// Height of the container
	var playerMinVersion = "9.0.0"; // Min flash player version
	var aFlashImgs = [];			// Array holding all images supposed to play Flash movies
	var imgFirst = null;			// Reference to the first image in the list of Flash movie images
	var url = "";					// URL to the Flash file to be played
	
	container = $("#" + containerID);
	
	if (container == null) { return false; }
	
	containerWidth = container.attr("movieWidth");
	containerHeight = container.attr("movieHeight");
	
	aFlashImgs = $(document).find("img.flash-img");		
	
	if (aFlashImgs.length > 0)
	{
		for (var i=0; i<aFlashImgs.length; i++)
		{
			if (i == 0)
			{
				// Get the first image that "plays" flash
				imgFirst = aFlashImgs[i];						
			}					
			
			// Add event handlers for these images					
			$(aFlashImgs[i]).click(function(event){ PlayFile(event, this)});
		}
	}
	
	// Create instance of player on page load
	if (imgFirst != null)
	{
		url = $(imgFirst).attr("flashFile");
		
		swfobject.embedSWF(url, containerID, containerWidth, containerHeight, playerMinVersion);
	}
		
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	// Name        : PlayFile
	// Description : Plays the file identified by the image clicked. The image contains the reference to the flash movie
	// Parameters  : 
	//				event = current event object
	//				img = current image element with attribute "flashFile".
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function PlayFile(event, img)
	{
		var url = "";
		
		if (img == null) { return false; }
		
		url = $(img).attr("flashFile");
		
		swfobject.embedSWF(url, containerID, containerWidth, containerHeight, playerMinVersion);			
	}		
});