/**
 * @fileoverview Wyświetla plik flasha.		
 *
 * @used IE, FF, Opera
 *
 * @example
 *		DisplayFlash.init({src: 'pliki/myFlash.swf', width: 400, height: 80});
 *		lub
 *		var df = new DisplayFlash({src: 'pliki/myFlash.swf', width: 400, height: 80});
 *		df.insertCode();
 *		
 * @version 1.0 2005/07/18
 */
 
Import('myLib/util/Random.js');
Import('myLib/native/Array.js');

/**
 * @constructor
 * @param	Array	Parametry flasha.
 */
DisplayFlash = function(params){ //System.subClass();
	/**
	 * Id obiektu flasha.
	 * @type	String
	 * @private
	 */
	this.classid = 'clsid:d27cdb6e-ae6d-11cf-96b8-444553540000';
	
	/**
	 * Domyślne atrybuty.
	 * @type	Array
	 * @private
	 */
	//width: 100,
	//height: 100,
	this.params = {
		id: Random.string(10),
		src: '',
		quality: 'high',
		wmode: 'transparent',
		bgcolor: '#ffffff'
	};
	
	for(var i in params){
		this.params[i] = params[i];
	}
};

/**
 * Ulatwia wyswietlanie flasha. Metoda pomocnicza.
 * @public
 * @param	Array	Parametry flasha.
 * @return	Object	Objekt klasy DisplayFlash.
 */
DisplayFlash.init = function(params){
	var df = new DisplayFlash(params);
	df.insertCode();
	return df; // df.getId();
};

/**
 * Wstawia pelen kod wyswietlajcy animacje flasha.
 * @public
 * @return	void
 */
DisplayFlash.prototype.insertCode = function(){
	document.write(this.getCode());
};

/**
 * Zwraca pełen kod wyswietlajacy animacje flasha.
 * @public
 * @return	void
 */
DisplayFlash.prototype.getCode = function(){
	return '<object ' + this.getParamsObject() + ' classid="' + this.classid + '" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0">' +
	'<param name="movie" value="' + this.params['src'] + '" />' +
	'<param name="quality" value="' + this.params['quality'] + '" />' +
	'<param name="wmode" value="' + this.params['wmode'] + '" />' +
	'<param name="bgcolor" value="' + this.params['bgcolor'] + '" />' +
	'<embed ' + this.getParamsEmbed() + ' type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>' +
	'</object>';

	/*
	var width = '';
	if(this.params['width']){
		width = 'width="' + this.params['width'] + '"';
	}
	var height = '';
	if(this.params['height']){
		height = 'height="' + this.params['width'] + '"';
	}
	
	return '<object id="' + this.params['id'] + '" ' + width + ' ' + height + ' classid="' + this.classid + '" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0">' +
	'<param name="movie" value="' + this.params['src'] + '" />' +
	'<param name="quality" value="' + this.params['quality'] + '" />' +
	'<param name="wmode" value="' + this.params['wmode'] + '" />' +
	'<param name="bgcolor" value="' + this.params['bgcolor'] + '" />' +
	'<embed name="' + this.params['id'] + '" src="' + this.params['src'] + '" quality="' + this.params['quality'] + '" wmode="' + this.params['wmode'] + '" bgcolor="' + this.params['bgcolor'] + '" ' + width + ' ' + height + ' type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>' +
	'</object>';
	*/
};

/**
 * Zwraca string zawierajacy liste atrybutow dla znacznika Object.
 * @private
 * @return	String
 */
DisplayFlash.prototype.getParamsObject = function(){
	var tmp = {};
	var keys = ['id', 'width', 'height'];
	for(var i = 0; i < keys.length; i++){
		if(typeof(this.params[keys[i]]) != 'undefined'){
			tmp[keys[i]] = this.params[keys[i]];
		}	
	}
	return Array.getString(tmp);
};

/**
 * Zwraca string zawierajacy liste atrybutow dla znacznika Embed.
 * @private
 * @return	String
 */
DisplayFlash.prototype.getParamsEmbed = function(){
	var tmp = {};
	for(var i in this.params){
		if(i == 'id')
			tmp['name'] = this.params[i];
		else
			tmp[i] = this.params[i];	
	}
	return Array.getString(tmp);
};

/**
 * Ustawia wartosc w tablicy this.param.
 * @public
 * @param	String	Klucz tablicy.
 * @param	Mixed	Wartosc wstawiona do tablicy.
 * @return	void
 */
DisplayFlash.prototype.setParam = function(key, value){
	this.params[key] = value;
};

/**
 * Zwraca element tablicy this.params.
 * @public
 * @param	String	Klucz tablicy this.params.
 * @return	String
 */
DisplayFlash.prototype.getParam = function(key){
	return this.params[key];
};

/**
 * Zwraca id obiektu reprezentujacego animacje flasha.
 * @public
 * @return	String
 */
DisplayFlash.prototype.getId = function(){
	return this.getParam('id');
};
