/*	File:					eyflashplayerapi.js
	Brief:					API for Flash player functionality
	Author:				Eddie Hermoso (eddie.hermoso@ey.com)
	Copyright:				Ernst & Young (2009)
	Document Referral:		flash_player_API.doc
	Text Characteristics:		4 Character Tabs, 104 Character Line Width
	Character Encoding:		ANSI
	Language:				JavaScript
	Editing Environment:		Notepad++ (http://notepad-plus.sourceforge.net/)
_____________________________________________________________________________________
	
	Version:	Date:				Author:			Summary:
	1.0.4		7/9/2009			Eddie Hermoso		fixed 4x3 height from 384 to 385
	1.0.2		4/3/2009			Eddie Hermoso		fix for SWF loading timer issue
	1.0.0		4/2/2009			Eddie Hermoso		initial release
_____________________________________________________________________________________
*/


var swfLoaded = false;
var interVar, interVar2, interVar3;
var myMovie = document.getElementById(swfPlayerName);

// Firefox does not load the SWF until after the the entire page has loaded
// this means that the SWF file cannot receive commands via the body.onload method
// therefore, we need to keep trying to play the media until the SWF has fully loaded
function playMovieOnload(mURL, aspect, imgURL)
{

	if (!swfobject.hasFlashPlayerVersion("9.0.18"))
		return;
		
	// if an image is not specified, set it to empty string
	if(!imgURL)
		imgURL = "";
		
	if(!aspect)
		aspect = "";
	
	// SWF may not exist yet on the page so we set it here
	myMovie = document.getElementById(swfPlayerName);
		

	// if the SWF object exists
	if(swfLoaded)
	{
		
		interVar2 = window.clearInterval(interVar2);
		
		//create a JS interval to attempt playing the media until the SWF is loaded
		if(imgURL != "")
		{
			clearInterval(interVar);
			interVar = window.setInterval("playWhenLoaded(\"" + mURL + "\", \"" + aspect + "\", \"" + imgURL + "\")", "300");
		}
		else
		{
			clearInterval(interVar);
			interVar = window.setInterval("playWhenLoaded(\"" + mURL + "\", \"" + aspect + "\")", "300");
		}
		
	} else {
		
		// if swfLoaded != true, call this function again
		clearInterval(interVar2);
		interVar2 = window.setInterval("playMovieOnload(\"" + mURL + "\", \"" + aspect +  "\", \"" + imgURL + "\")", "300");

	}
	
}

function playWhenLoaded(mURL, aspect, imgURL)
{
	myMovie = document.getElementById(swfPlayerName);
	
	// if we are able to receive the value of the variable from the SWF, it means the SWF is already loaded
	if(swfLoaded)
	{
	
		// terminate the interval
		clearInterval(interVar);
		clearInterval(interVar2);

		// play the media asset
		if(imgURL == "" || imgURL == null)
		{
			playMovie(mURL, aspect);
		} 
		else
		{
			loadSWFOnly(mURL, imgURL, aspect);
		}
				
	}
	
}


function loadSWFOnly(mediaURL, imageURL, aspect)
{
	myMovie = document.getElementById(swfPlayerName);
	
	if(swfLoaded){
			
		clearInterval(interVar);
		clearInterval(interVar2);
		
		try
		{
			myMovie.changeSource(mediaURL);
			myMovie.showImage(imageURL);
		
		}
		catch(e)
		{
		
			clearInterval(interVar);
			clearInterval(interVar2);
			alert("loadSWFOnly: " + e.message);
			
		}
		
		if(aspect != null)
		{
			if(aspect == "regular")
			{
				setRegularScreen();
			}
			else if(aspect == "wide")
			{
				setWideScreen();
			}
		}
		
	}
}

function playMovie(mURL, aspect)
{

	myMovie = document.getElementById(swfPlayerName);

	if(swfLoaded){
	
		clearInterval(interVar);
		clearInterval(interVar2);
		
		try
		{
			if(aspect != null)
			{
				if(aspect == "regular")
				{
					setRegularScreen();
				}
				else if(aspect == "wide")
				{
					setWideScreen();
				}
			}
		
			stopMedia();
			myMovie.startVideo(mURL);
		}
		catch(e)
		{
			clearInterval(interVar);
			clearInterval(interVar2);
			alert("playMovie: " + e.message);
		}
	}
}


function seekTo(spot)
{
	myMovie.seekTo(spot);
}

function stopMedia()
{
	myMovie.stopPlayer();
}

function pauseMedia()
{
	myMovie.pauseMedia();
}

function playMedia()
{
	myMovie.playMedia();
}

function muteMedia()
{
	myMovie.muteMedia();
}

function unmuteMedia()
{
	myMovie.unmuteMedia();
}

function setVolume(level)
{
	myMovie.setVolume(level/100);
}

function fullScreenOn()
{
	myMovie.fullScreenOn();
}

function fullScreenOff()
{
	myMovie.fullScreenOff();
}

function setWideScreen()
{
	myMovie.setWideScreen();
	myMovie.height = 298;
}

function setRegularScreen()
{
	myMovie.setRegularScreen();
	myMovie.height = 385;
}

// called from within the flv_player.swf file
function swfHasLoaded(bool){

	swfLoaded = true;

}