/**
 * the id is the string form of the var name
 * it will be called by flash to communicate with the instance
 * var sw = SwfPlayerObject("sw");
 */ 
function SWFPlayerObject(instanceId,id,width,height,version,bgcolor) {
	
	// required. for flash to reference the page.
	if(!instanceId)
		return;
		
	this.wmp = null;
	this.coad = null;
	
	version = version ? version : "8";
	width = width ? width : 300;
	height = height ? height : 300;
	bgcolor = !isNaN(bgcolor) ? bgcolor : "#000000";
	
	var so = new SWFObject("/player/embed/", id, width, height, version, bgcolor);
	
	if(location.search.indexOf("jsDebugOn")!=-1)
		so.addVariable("jsDebuggerFunction",instanceId+".log");
	
	if(location.search.indexOf("lcDebugOn=true")!=-1)
		so.addVariable("lcDebugOn","true");
	
	this.setPath = function(path) {
		so.setAttribute('swf', path);
	}
	
	// a javascript reference to this by string.
	so.addVariable("jsInstanceId",instanceId)
	
	// a reference to the embedded plug in
	so.addVariable("elementId",id);
	
	this.addParam = function(name,value) {
		so.addParam(name,value);
		so.addVariable(name,value);
	}
	
	this.addVariable = function(name,value) {
		so.addVariable(name,value);
	}
	
	this.setAttribute = function(name,value) {
		so.setAttribute(name,value);
	}
	
	this.addWMPSupport = function(target) {
		this.wmp = new WMPBrowser(target,id);
	}
	
	this.addCoAd = function(target) {
		this.coad = new CoAdBrowser(target);
	}
	
	this.write = function(target) {
		so.write(target);
	}
	
	this.openAndFocus = function(url,name,features){
		var o = window.open(url, name, features);
		o.focus();
	}
	
	this.log = function(statement){
		
		if(document.getElementById("ta") && statement){
			document.getElementById("ta").value += ('\n'+statement);	
		}else{
			var d = document.createElement('div');
			var width = "100%";
			var height = 200;
			var left = 10;
			var top = screen.availHeight - height - ((window.ActiveXObject) ? 60 : 90);
			var newStyle = 'display:inline;position:absolute;z-index:300;left:' + left + 'px;top:' + top + 'px;width:' + width + 'px;height:' + height + 'px;';	
			d.style.cssText = newStyle;
			document.body.appendChild(d);	
			
			// textarea
			var ta= document.createElement('textarea');
			ta.setAttribute("name","ta");
			ta.setAttribute("id","ta");
			ta.setAttribute("cols","130");
			ta.setAttribute("rows","8");
			ta.setAttribute("wrap","off");
			d.appendChild(ta);	
			var db= document.createElement('button');
			db.setAttribute("name","db");
			db.setAttribute("id","db");
			var buttext = document.createTextNode('clear');
			db.appendChild(buttext);
			db.onclick = function () {
				document.getElementById("ta").value = "";
			};
		
			d.appendChild(db);	
			if(statement){
				ta.value+=statement;
			}
		}
	}
};