function SwfBrowser() { 
	SwfBrowser.swfBrowserArray.push(this);
}

SwfBrowser.swfBrowserArray = new Array();
SwfBrowser.initReadyCalled = false;

SwfBrowser.initRequest = function() {
	return true;
}

//*************************************


SwfBrowser.prototype.createWindow = function(parentWindow,name,position,left,top,width,height,flashVarArray,src,args,flashVersion) {
	this.name = name;
	this.wmode = args ? args : "transparent";
	this.flashVersion = flashVersion ? flashVersion : 7;

	if(!flashVarArray)
		flashVarArray = new Array();


	if(src){
		this.swfSrc = src;
		//flashVars = 'documentSrc=' + this.initialUrl;	
	}else{
		this.swfSrc = browserManager.pathToFrameWork + browserManager.swfName;
	}

	if(BrowserManager.version){
		var concatStr = (this.swfSrc.indexOf('?')>=0) ? '&' : '?'; 
		this.swfSrc += concatStr + '_EsiFBMLVersion=' + BrowserManager.version;
		flashVarArray["_EsiFBMLVersion"] = BrowserManager.version;
	}

	flashVarArray["name"] = name;

	var isIE = (navigator.userAgent.toLowerCase().indexOf("msie")!=-1);
	flashVarArray["isIE"] = isIE;

	var flashVars = SwfBrowser_buildFlashVarString(flashVarArray);

	if(browserManager.swfQuality==undefined)
		this.quality = "autohigh";
	else 
		this.quality = browserManager.swfQuality;

	var buff = '<div id="' + this.name + '_div" style="height:' + height + 'px;width=' + width + 'px;position:relative;left:' + 0 + 'px;top:' + 0 + 'px;">\n'; 
	
	if(isIE){
		buff+='<object id="' + this.name + '" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + this.flashVersion + ',0,0,0" width="' + width  + '" height="' + height + '" align="middle">\n' + 
		'<' + 'param name="movie" value="' + this.swfSrc + '" />\n' +
		'<' + 'param name="swLiveConnect" value="true" />\n' +
		'<' + 'param name="flashVars" value="'+ flashVars + '" />\n' +
		'<' + 'param name="quality" value="' + this.quality + '" />\n' +
		'<' + 'param name="scale" value="noscale" />\n' +
		'<' + 'param name="salign" value="lt" />\n' +
		'<' + 'param name="menu" value="false" />\n' +
		'<' + 'param name="wmode" value="' + this.wmode + '" />\n' +
		'<' + 'param name="allowFullScreen" value="true" />\n' +  
		'<' + 'param name="SeamlessTabbing" value="false" />\n';
		
		if(SwfBrowser.bgcolor)
			buff += '<' + 'param name="bgcolor" value="' + SwfBrowser.bgcolor + '" />\n'
	}else{

	buff += '<' + 'embed sr' + 'c="' + this.swfSrc + '" quality="' + this.quality + '" ' + 
	'flashVars="'+ flashVars + '"' + 
	'wmode="' + this.wmode + '" scale="noscale" salign="lt" width="' + width + '" height="' + height + '" '
	}
	
	if(SwfBrowser.bgcolor)
		buff += 'bgcolor="' + SwfBrowser.bgcolor + '" '

	
	buff += 'align="middle" menu="false" type="application/x-shockwave-flash" allowFullScreen="true" AllowScriptAccess="always" ' + 
	'pluginspage="http://www.macromedia.com/go/getflashplayer" swLiveConnect="true" id="' + this.name + '" SeamlessTabbing="false" />\n';

	if(isIE)
		buff+='</object>\n'; 
		
	buff+='</div>\n';
	document.getElementById(parentWindow).innerHTML = buff;
	document.write(this.writeFSCommand());	
}

function SwfBrowser_buildFlashVarString(flashVars) {

	var buff = "";

	for(i in flashVars)
		buff += i + "=" + escape(flashVars[i]) + "&";

	return buff.slice(0,buff.length-1);

}
function SwfBrowser_getPlugin(id){
	
	try {
		Debug.trace("document.getElementById(" + id + ") = " + document.getElementById(id))
		return document.getElementById(id);	
		
	}catch(e) {
		Debug.trace("window.document[" + id + "] = " + window.document[id])
		return window.document[id];	
	}
	
}
function SwfBrowser_setVariable(id,name,value) {
	alert('SwfBrowser_setVariable(' + id + ',' + name + ',' + value + ')');		
	if(navigator.platform.toLowerCase().indexOf('win') != -1){			
		try {
			document.getElementById(id).SetVariable(name, value);	
		}catch(e) {
			window.document[id].SetVariable(name, value);	
		}
	}else{
		var diff = (new Date().getTime()-this.time);

		if(diff<20){
			this.divId++;
			SwfBrowser_writeLocalConnectionDiv(this.divId,id,name,value);
		}else{
			this.divId=0;
			SwfBrowser_writeLocalConnectionDiv(0,id,name,value);
		}
		
		this.time = new Date().getTime();
	}
}
SwfBrowser_writeLocalConnectionDiv = function (divid,id,name,value) {

	var gateway = browserManager.pathToFrameWork + "gateway.swf";

	var divcontainer = "flash_setvariables_"+divid;
	if(!document.getElementById(divcontainer)){
			var divholder = document.createElement("div");
			divholder.id = divcontainer;
			document.body.appendChild(divholder);
	}

	document.getElementById(divcontainer).innerHTML = "";
	var flashquery = name + '=' + value;
	var divinfo = '<embed sr' + 'c="' + gateway + '" FlashVars="lc='+id+'&fq='+escape(flashquery)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
	document.getElementById(divcontainer).innerHTML = divinfo;

}; 

SwfBrowser.prototype.navigate = function(navigateToUrl) {
	var p = SwfBrowser_getPlugin(this.name)
	Debug.trace("p - " + p)
	p.navigate(navigateToUrl);
}

SwfBrowser.prototype.command = function(target,commandName,args) {
	SwfBrowser_getPlugin(this.name).command(target,commandName,args);
}

SwfBrowser.prototype.setBrowserProperty = function(target,property,args) {
	SwfBrowser_getPlugin(this.name).setBrowserProperty(target,property,args);
}

SwfBrowser.prototype.writeFSCommand = function() {
	var buff = "<sc" + "ript language=\"javascript\">\n" + 
			"\tfunction " + this.name + "_DoFSCommand(command, arguments) {\n" + 
			//"\t\tprompt('',arguments);\n" + 				
			"\t\tvar args = arguments.split(\",\");\n" + 
			"var scriptCall = command + \"(\" + args + \")\";\n" + 
			"eval(scriptCall);\n" + 
			"\t}\n" + 
			"<" +  "/script>\n"; 
	if (navigator.appName && navigator.appName.indexOf("Microsoft") != -1 && navigator.userAgent.indexOf("Windows") != -1 && navigator.userAgent.indexOf("Windows 3.1") == -1) {
		document.write('<' + 'script language=\"VBScript\"\>\n');
		document.write('On Error Resume Next\n');
		document.write('Sub ' + this.name + '_FSCommand(ByVal command, ByVal args)\n');
		document.write('\tCall ' + this.name + '_DoFSCommand(command, args)\n');
		document.write('End Sub\n');
		document.write('<' + '/script\>\n');
	}
	return buff;
}

SwfBrowser.prototype.onPageLoad = function() { }
SwfBrowser.prototype.updateWindow = function() { }
SwfBrowser.prototype.destroyWindow = function() { }
