//Global variables.
var xmlDoc;
var swfID;

function embedFlashObject(asset, height, width, color)
{
	var name = asset.replace('.swf', '');
	
	swfID = name = name.replace(" ","");
	
	document.write("<div class='jsas' id='jsas'>");
		document.write("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0'");
			document.write("width='"+ width +"'");
			document.write("height='"+ height +"'");
			document.write("id='"+name+"'");
			document.write("align='middle'>");
		
			document.write("<param name='allowScriptAccess' value='always' />");
			document.write("<param name='src' value='"+ asset +"' />");
			document.write("<param name='quality' value='high' />");
			document.write("<param name='bgcolor' value='" + color + "' />");
			document.write("<param name='flashVars' value='xmlPath=runtimeDocs/resources.xml'>");
			
			document.write("<embed src='"+ asset +"'");
			document.write("quality='high'");
			document.write("bgcolor='" + color + "'");
			document.write("flashVars='xmlPath=runtimeDocs/resources.xml'");
			document.write("width='"+ width +"'");
			document.write("height='"+ height +"'");
			document.write("name='"+ name +"'");
			document.write("align='middle'");
			document.write("allowScriptAccess='always'");
			document.write("type='application/x-shockwave-flash'");
			document.write("pluginspage='http://www.macromedia.com/go/getflashplayer' />");
		document.write("</object>");
	document.write("</div>");
}

function thisMovie(movieName) 
{
	if (navigator.appName.indexOf("Microsoft") != -1 || navigator.appVersion.indexOf("Safari") != -1) 
    {
		return document.getElementById(movieName);
    }
    else 
    {
		return document.embeds[movieName];
    }
}

// Called by the Flash Movie if there is an error loading the XML data
function xmlError()
{	
	alert("An error has occurred in loading the XML file. Please reload the page to try again.");
}

// Send the tokenJS to the Flash Movie to let it know the page has finished loading
function sendJSToken()
{	
	var flashMovie = thisMovie(swfID);
	flashMovie.sendJSToken();
}

// Called from the onLoad() event when the page has fully loaded 
function setToken() 
{
	tokenJS = true;
	
	if (tokenAS == true)
	{
		sendJSToken();
		hideFlashDIV();
		displayXML();
	}		
}
// Called from the Flash Movie to let the page know it has loaded the XML data
function setASToken()
{
	tokenAS = true;
	
	if (tokenJS == true) 
	{
		sendJSToken();
		hideFlashDIV();
		displayXML();
	}
}

// Hide the flash DIV.
function hideFlashDIV()
{
	var flashLayer = document.getElementById("jsas");

	flashLayer.style.visibility = "hidden";
}
