var width = "";
var height = "";
var version = "8.0.0";
var divNum = -1;

/*Called from the webpage to embed flash within the page*/
function embedFlash(fileName, type)
{
	var flashvars = {};
	var params = {};
	var attributes = {};
	var SWFName = "";
	var ext = fileName.substring(fileName.length - 4, fileName.length);
	divNum++;
	var divName = "flash" + divNum;
	
	/*check the type requested and adjust seetings*/
	if(type == "module")
	{
		setModule();
	}
	else if(type == "video")
	{
		setVideo();	
	}
	else if(type == "banner")
	{
		setHomeBanner();	
	}
	else if(type == "full")
	{
		setFull(divName);
	}
	else
	{
		type = "default"
		setDefault();
	}

	/*check whether the video file is a SWF or FLV*/
	if(ext == ".flv")
	{
		/*specify source of FLV*/
		flashvars.flashSrc = fileName;
		/*set background to be transparent*/
		params.wmode = 'transparent';
		/*specify which FLV container to use*/
		SWFName = "/flash/FLVplybk_" + type + ".swf";
		/*add 40 to height to accomodate play controls*/
		height = (parseInt(height) + 40) + "";
	}
	else if(ext == ".swf")
	{
		SWFName = fileName;
	}
	else
	{
		/*incorrect file extension found*/
		return;
	}
	
	/*set base directory to that of the SWF file - allows the flash files to be in a different location than the web page*/
	params.base = SWFName.substring(0, SWFName.lastIndexOf("/")+1);
	
	/*output the video to the page*/
	writeDiv(divName);
	swfobject.embedSWF(SWFName, divName, width, height, version, false, flashvars, params, attributes);
}

/*Write the div that will hold the video.
Displays flash update message if user has an outdated version of the flash plugin.*/
function writeDiv(divName)
{
	document.write('<div id="' + divName + '">' +
		'<p class="bodytext-italic">This page contains flash material and requires the Adobe Flash player in order to be viewed.</p>' +
		'<p><a href="http://www.adobe.com/go/getflashplayer" onClick="return popup(this.href, \'external\');" target="_blank"><img src="http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif" alt="Get Adobe Flash player" /></a></p>' +
	'</div>');
}

/*Default type settings*/
function setDefault()
{
	width = "320";
	height = "260";
}

/*Full type settings*/
function setFull(divName)
{
	width = "100%";
	height = "100%";
	document.write('<style type="text/css">#' + divName + ' {position:absolute; top:0px; bottom:0px; left:0px; right:0px; width:100%; height:100%;}</style>');
}

/*Module type settings*/
function setModule()
{
	width = "640";
	height = "480";
}

/*Video type settings*/
function setVideo()
{
	width = "480";
	height = "360";
}

/*Home Banner type settings*/
function setBanner()
{
	width = "680";
	height = "200";
}
