// parent class to other flash objects
function FlashObj(id, flashVars, width, height, movie, wmode, classid, codebase,
		align, allowScriptAccess, bgcolor, quality, scale, salign, target, imgBase){
	// see http://livedocs.macromedia.com/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001002.html
	// for a detailed list of properties.
	// id - String, id of object in dom
	// flashVars - Object, key value pairs representing the flashVars
	// width - Number, width of object.
	// height - Number, height of object.
	// classid - String, Defines the classid of Flash Player. This identifies 
	//		the ActiveX control for the browser. Defaults to "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
	// codebase - String, Identifies the location of Flash Player ActiveX 
	//		control so that the browser can download it if it is not already installed.
	//		Defaults to "http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,16,0"
	// movie - String, uri of flash swf file
	// align - String, Specifies the position of the SWF file. The align 
	//		property supports the following values:
	//		bottom: Vertically aligns the bottom of the SWF file with the 
	//			current baseline. This is the default value.
    //		middle: Vertically aligns the middle of the SWF file with the
    //			current baseline.
    //		top: Vertically aligns the top of the SWF file with the top 
    //			of the current text line.
    //		left: Horizontally aligns the SWF file to the left margin.
    //		right: Horizontally aligns the SWF file to the right margin.
    //		Defaults to middle
	// allowScriptAccess - String, "always": permits the SWF file to interact with the HTML page in all cases.
	//		"sameDomain": permits the SWF file to interact with the HTML page only when their domains 
	//			match exactly. By default, the HTML publish templates in the Adobe Flash authoring application 
	//			output HTML that specifiesAllowScriptAccess="sameDomain", as this is frequently the desired 
	//			security behavior. 
	//		"never": completely prevents the SWF file from interacting with the HTML page.
	// 
	// bgcolor - String, background color in hexadecimal. Default is #ffffff
	// quality - String, Defines the quality of playback in Flash Player. Valid values of quality are low, medium, 
	//		high, autolow, autohigh, and best. The default value is high.
	// scale - String, Defines how the browser fills the screen with the SWF file. The default value is showall. 
	//		Valid values of the scale property are showall, noborder, and exactfit.
	// salign - String, Positions the SWF file within the browser. Valid values are L, T, R, B, TL, TR, BL, and BR.
	//		The default value is TL.
	// wmode - String, Sets the Window Mode property of the SWF file for transparency, layering, and positioning 
	//		in the browser. Valid values of wmode are window, opaque, and transparent. Default is window.
	this.flashVars = flashVars;
	flashVarsStr = FlashObj.GenFlashVars(this.flashVars);
	this.width = width;
	this.height = height;
	align = align || "middle";
	allowScriptAccess = allowScriptAccess || "always";
	bgcolor = bgcolor || "#ffffff";
	quality = quality || "high";
	scale = scale || "noscale";
	salign = salign || null;
	wmode = wmode || "window";
	classid = classid || "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000";
	codebase = codebase || "http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab";
	this.imgBase = imgBase;
	this.allowFullScreen = "true";
	
	this.parameters = {movie:movie,
						allowScriptAccess:allowScriptAccess,
						quality:quality,
						bgcolor:bgcolor,
						FlashVars:flashVarsStr,
						scale:scale,
						salign:salign,
						wmode:wmode,
						allowFullScreen:this.allowFullScreen};
	this.attributes = {classid:classid,
						codebase:codebase,
						height:height,
						width:width,
						id:id,
						align:align};
						
	this.target = target;
};

FlashObj.prototype.toString = function(){
	// TODO modify this to check for any version of flash
	// map object attributes and parameters to embed attributes
	if (FlashDetection.hasRequiredVer()){
		var embed = {allowScriptAccess:this.parameters['allowScriptAccess'],
				 allowFullScreen:this.parameters['allowFullScreen'],
				 src:this.parameters['movie'],
				 quality:this.parameters['quality'],
				 bgcolor:this.parameters['bgcolor'],
				 FlashVars:this.parameters['FlashVars'],
				 width:this.attributes['width'],
				 height:this.attributes['height'],
				 name:this.attributes['id'],
				 align:this.attributes['align'],
				 scale:this.parameters['scale'],
				 salign:this.parameters['salign'],
				 wmode:this.parameters['wmode'],
				 type:"application/x-shockwave-flash",
				 pluginspage:"http://www.macromedia.com/go/getflashplayer"};
		var playerStr = "<object " + PlayerUtil.genAtrs(this.attributes) + " >";
			playerStr += PlayerUtil.genParams(this.parameters);
			playerStr += "<embed " + PlayerUtil.genAtrs(embed) + " />";
			playerStr += "</object>";
	
		return playerStr;
	} else {
		return this.toStringNoFlash();
	}
}

FlashObj.prototype.write = function(documentRef){
	if (documentRef == null)
		documentRef = document;
	documentRef.writeln(this.toString());
}

// IE does not support creation of Object element using the dom,
// therefore we must create a container object and set the innerHTML of the object
// to the generated string.
FlashObj.prototype.createElement = function(){
	var elem = document.createElement("div");
	this.drawInElem(elem);
	return elem;
}

FlashObj.prototype.drawInElem = function(elem) {
	UIUtil.getElem(elem).innerHTML += this.toString();
}

FlashObj.prototype.toStringNoFlash = function(){
	return FlashDetection.getFlashStr(this.attributes.width, this.attributes.height, this.imgBase);
}

FlashObj.prototype.createElementNoFlash = function(){
	var elem = document.createElement("div");
	elem.innnerHTML = this.toStringNoFlash();
	return elem;
}

FlashObj.GenFlashVars = function(flashVars){
	var rtnStr = "";
	for (var key in flashVars) {
		if(rtnStr != "")
			rtnStr += "&";
		rtnStr += encodeURIComponent(key) + "=" + encodeURIComponent(new String(flashVars[key]).replace(/[+]/g, '%2B')).replace(/%252B/g,'%2B');
	}
	return rtnStr;
}

FlashObj.handleClickOn = function(url, target, name, features, replace) {
	if((target == undefined) || (target == null))
		window.location = url;
	else if(target == "_parent")
		window.parent.location = url;
	else if(target == "_top")
		window.top.location = url;
	else if(target == "_blank")
		window.open(url, name, features, replace);
	else
		window.top.location = url;
	
}

FlashObj.getObjById = function(id){
	return UIUtil.isIE() ? window[id] : document[id];
}
