// ************************************************************************************ //
//
// File name: flash_writer.js
// Version: 1.0
// Date: 03/08/2005
// Author: Christian Madden 
// 
// ************************************************************************************ //

// ************************************************************************************ //
// Objects and functions to facilitate the dynamic creation of Flash tags
// Depends:
//	flash_init.js
// ************************************************************************************ //

/* ************************************************************************** */
// FlashWriter object
/* ************************************************************************** */
function FlashWriter()
{
	this.params = new Array();
	
	// Initialize with default parameters
	this.setDefaultParams();
}
/* ************************************************************************** */


/* ************************************************************************** */
// Public interface
FlashWriter.prototype.getTag = FlashWriter_getTag;

// Internal
FlashWriter.prototype.addParam = FlashWriter_addParam;
FlashWriter.prototype.addParams = FlashWriter_addParams;
FlashWriter.prototype.getParam = FlashWriter_getParam;
FlashWriter.prototype.setDefaultParams = FlashWriter_setDefaultParams;
FlashWriter.prototype.createObjectTag = FlashWriter_createObjectTag;
/* ************************************************************************** */


/* ************************************************************************** */
// Function to generate a flash tag
// Args:
// 	movie - the path to the flash file
// 	width - width of the flash 
// 	height - height of the flash 
// 	OPTIONAL
// 	params - associative array of parameters, keys must correspond to the values set
//			 in  FlashWriter_setDefaultParams or they will not be used
// 
/* ************************************************************************** */
function FlashWriter_getTag(movie, width, height, params)
{	
	this.addParam("movie", movie);
	this.addParam("width", width);
	this.addParam("height", height);
	this.addParams(params);
	
	return this.createObjectTag();
}
/* ************************************************************************** */


/* ************************************************************************** */
// Function to add/overwrite a parameter to the Writer object's internal list
// Args:
// 	name - key value for a parameter
// 	value - value of the parameter
/* ************************************************************************** */
function FlashWriter_addParam(name, value)
{
	this.params[name] = value;
}
/* ************************************************************************** */


/* ************************************************************************** */
// Function to add/overwrite a list of parameters to the Writer object's internal list
// Args:
// 	params - associative array of parameters, keys must correspond to the values set
//			 in  FlashWriter_setDefaultParams or they will not be used
/* ************************************************************************** */
function FlashWriter_addParams(params)
{	
	if(params)
	{
		for(key in params)
		{
			this.addParam(key, params[key]);
		}
	}
}
/* ************************************************************************** */


/* ************************************************************************** */
// Function to get a parameter value from the Writer object's internal list
// Args:
// 	key - key value for a parameter to be retireved
/* ************************************************************************** */
function FlashWriter_getParam(key)
{
	return (this.params[key]) ? this.params[key] : "";
}
/* ************************************************************************** */


/* ************************************************************************** */
// Function to initialize all currently valid parameters to the Flash Tag
/* ************************************************************************** */
function FlashWriter_setDefaultParams()
{
	this.addParam("classid", _CLASSID);
	this.addParam("codebase", _CODEBASE);
	this.addParam("play", _PLAY);
	this.addParam("loop", _LOOP);
	this.addParam("quality", _QUALITY);
	this.addParam("menu", _MENU);
	this.addParam("bgcolor", _BGCOLOR);
	this.addParam("wmode", _WMODE);
	this.addParam("flashvars", _FLASHVARS);
	this.addParam("allowScriptAccess", _ALLOW_SCRIPT_ACCESS);
	this.addParam("type", _TYPE);
	this.addParam("pluginspage", _PLUGINSPAGE);
}
/* ************************************************************************** */


/* ************************************************************************** */
// Function to create the Flash tag as HTML code
/* ************************************************************************** */
function FlashWriter_createObjectTag()
{
	var tag = '<object classid="' + this.getParam("classid") + '" '
		   + 'width="' + this.getParam("width") + '" ' 
		   + 'height="' + this.getParam("height") + '" '
		   + 'codebase="' + this.getParam("codebase") + '">\n'
		   + '<param name="movie" value="' + this.getParam("movie") + '" />\n'
		   + '<param name="FlashVars" value="' + this.getParam("flashvars") + '" />\n'
		   + '<param name="play" value="' + this.getParam("play") + '" />\n'
		   + '<param name="loop" value="' + this.getParam("loop") + '" />\n'
		   + '<param name="quality" value="' + this.getParam("quality") + '" />\n'
		   + '<param name="menu" value="' + this.getParam("menu") + '" />\n'
		   //+ '<param name="wmode" value="' + this.getParam("wmode") + '" />\n'
		   + '<param name="bgcolor" value="' + this.getParam("bgcolor") + '" />\n'
		   + '<param name="allowScriptAccess" value="' + this.getParam("allowScriptAccess") + '" />\n'
		   + '<embed src="' + this.getParam("movie") + '" '
		   + 'width="' + this.getParam("width") + '" height="' + this.getParam("height") + '" '
		   + 'FlashVars="' + this.getParam("flashvars") + '" '
		   + 'play="' + this.getParam("play") + '" '
		   + 'loop="' + this.getParam("loop") + '" '
		   + 'quality="' + this.getParam("quality") + '" '
		   + 'menu="' + this.getParam("menu") + '" '
		   //+ 'wmode="' + this.getParam("wmode") + '" '
		   + 'bgcolor="' + this.getParam("bgcolor") + '" '
		   + 'allowScriptAccess="' + this.getParam("allowScriptAccess") + '" '
		   + 'type="' + this.getParam("type") + '" '
		   + 'pluginspage="' + this.getParam("pluginspage") + '">\n'
		   + '</embed>\n'
		   + '</object>\n';
	return tag;
}
/* ************************************************************************** */