var flashLoaded = new Object();
function onUnloaded() {
window.onunload = null;
}

//  after finding the flash movie on the page, sends message to that movie
function callExternalInterface(file, functionName) {
	//alert(file+", "+functionName);
	flashMovie=thisMovie(file);
    if(flashMovie&&flashMovie[functionName]){flashMovie[functionName]();}
}
// finds flash object on page and differentiates between IE and Firefox
function thisMovie(movieName) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        return window[movieName];
    }
    else {
        return document[movieName];
    }
}
// talk to flash and tell it to hide or show panel

function toggleFlash(file, dv, w, h, bgc, flashPath, comp, wmode, vars, functionName, webrootVar, nameSpace){
	if (flashLoaded[file]=="loaded") {
		callExternalInterface(file, functionName);
	} else { 
		flashLoaded[file]="loaded"; //not loaded, so set to loaded
		insertFlashTag(file, dv, w, h, bgc, flashPath, comp, wmode, vars, functionName, webrootVar);
	}
}

//	Work around for IE active content bug

function insertFlashTag(file, dv, w, h, bgc, flashPath, comp, wmode, vars, functionName, webrootVar, nameSpace){
	holder=(flashPath+file+".swf");
	if (wmode==null) {
		wmode="transparent";
	}
	// comp="+comp+"&dv="+dv+"&file="+file+"
	//alert("loading flash:"+holder);
	var objTag = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" id=\""+file+"\" width=\""+w+"\" height=\""+h+"\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab\">\n" +
		"<param name=\"movie\" value=\""+holder+"\" /><param name=\"FlashVars\" value=\"comp="+comp+"&dv="+dv+"&webroot="+webrootVar+"&nameSpace="+nameSpace+"&file="+file+parseFlashVarsToString(vars)+"\" /><param name=\"quality\" value=\"high\" /><param name=\"wmode\" value=\""+wmode+"\" /><param name=\"salign\" value=\"t\" /><param name=\"scale\" value=\"noscale\" /><param name=\"bgcolor\" value=\""+bgc+"\" />\n" +
		"<embed src=\""+holder+"\" FlashVars=\"comp="+comp+"&dv="+dv+"&webroot="+webrootVar+"&nameSpace="+nameSpace+"&file="+file+parseFlashVarsToString(vars)+"\" quality=\"high\" wmode=\""+wmode+"\" salign=\"t\" bgcolor=\""+bgc+"\" width=\""+w+"\" height=\""+h+"\" name=\""+file+"\" align=\"top\" play=\"true\" loop=\"false\" scale=\"noscale\" quality=\"high\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\">\n" +
		"</embed></object>";
	var flashDiv = document.getElementById(dv);
	if(flashDiv) {
	flashDiv.style.width = w+"px";
	flashDiv.style.height = h+"px";
	flashDiv.innerHTML = objTag;
    }
}
function insertFlashTagStretch(file, dv, flashPath){
	holder=(flashPath+file+".swf");
	var objTag = "<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\" width=\"100%\" height=\"100%\" title=\"flash\">\n" +
	"<param name=\"movie\" value=\""+holder+"\" />\n" +
	"<param name=\"quality\" value=\"high\" />\n" +
	"<embed src=\""+holder+"\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\" width=\"100%\" height=\"100%\"></embed>\n" +
	"</object>";
	var flashDiv = document.getElementById(dv);
	if(flashDiv) {
	flashDiv.innerHTML = objTag;
    }
}
function parseFlashVarsToString(vars){
	if(!vars)return "";
	var retStr = "";
	var first = true;
	for(varItem in vars){
		retStr+="&"+varItem+"="+vars[varItem];
		}
	return retStr;
}

function jAlert(alrt) {
	alert(alrt);
	}

