//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/package.xml'>");
			
			document.write("<embed src='"+ asset +"'");
			document.write("quality='high'");
			document.write("bgcolor='" + color + "'");
			document.write("flashVars='xmlPath=runtimeDocs/package.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 embedFlashObject2(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/informationText.xml'>");
			
			document.write("<embed src='"+ asset +"'");
			document.write("quality='high'");
			document.write("bgcolor='" + color + "'");
			document.write("flashVars='xmlPath=runtimeDocs/informationText.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];
    }
}

function testFromJS() 
{
	//thisMovie("prototypedemo").getNode(["neil was here", "so was robert"]);
	//thisMovie("prototypedemo").getNode("menu/links/item");
	//thisMovie("prototypedemo").getNode("menu/links/item/textlink");
	//var nm = thisMovie(swfID).getNode("menu/links/item/textlink/text()");
	//var nm = thisMovie(swfID).getNode("menu/setup/info[@id='wave']", "attrib");
	
	var nm = thisMovie(swfID).getNode("root/project[@name='Alis']/video", "attrib");
	var robertArray = new Array();
	var robertArray2 = new Array();
	
	/*for (var i in nm) 
	{
		alert(i + " : "+ nm[i]);
		robertArray[i] = nm[i];
	}*/
	
	/*for (i=0; i<nm.nodeInfo.length; i++) 
	{
		alert(nm.nodeInfo[i]);
	}*/
	
	for (var i in nm.nodeInfo)
	{
		alert(i + " : "+ nm.nodeInfo[i]);
		robertArray2[i] = nm.nodeInfo[i];	
	}
	
	alert(robertArray2[0]);
}

function returnFromFlash(obj) 
{
	for (var i in obj) 
	{
		alert(i + " : "+ obj[i]);
	}
	
	for (i=0; i<obj.nodeInfo.length; i++) 
	{
		alert(obj.nodeInfo[i]);
	}
	
	for (var i in obj.nodeInfo) 
	{
		alert(i + " : "+ obj.nodeInfo[i])	
	}
	
	//return(true);
}

// Functions that are called by SWF files
function xmlLoadComplete(success,data) 
{
	if (success) 
	{
		//alert("XML data was loaded successfully by the SWF");
		//alert(data);
	}
	else 
	{
		//alert("Error occurred while loading XML data");
	} 
}

// 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. Please try refreshing your browser.");
}

// 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"
}
