/*
 * Swf object
 */
var Swf = function() {

	var defaults = {
		'id': 'noid',
		'name': 'noname',
		'flashvars': {},
		'allowscriptaccess': 'always',
		'allowfullscreen': 'true',
		'quality': 'high',
		'bgcolor': '',
		'style': '',
		'width': 100,
		'height': 100,
		'src': '',
		'type': 'application/x-shockwave-flash'
	};

	var options = arguments[0] || {};

	// set options
	for(key in defaults) {
		options[key] = (typeof options[key] != 'undefined') ? options[key] : defaults[key] ;
	}

	var get_flashvars = function() {
		// assume string
		var flashvars = options['flashvars'];

		// check if vars are JSON object
		if(typeof flashvars == 'object') {
			var tmp = [];

			for(x in flashvars) {
				tmp[tmp.length] = x + '=' + flashvars[x];
			}

			// set string
			flashvars = tmp.join('&');
		}

		return flashvars;
	};

	var build = function() {
		// open object tag
		var obj = '	<object id="' + options['id'] + '" name="' + options['name'] + '" ';
		obj += 'width="' + options['width'] + '" height="' + options['height'] + '">';

		// flashvars string
		var flashvars = get_flashvars();

		// object params
		var param = '<param name="movie" value="' + options['src'] + '" />';
		param += '<param name="allowfullscreen" value="' + options['allowfullscreen'] + '" />';
		param += '<param name="allowscriptaccess" value="' + options['allowscriptaccess'] + '" />';
		param += '<param name="flashvars" value="' + flashvars + '" />';
		obj += param;

		// embed tag
		var embed = '<embed ';

		// embed attributes
		var attr = [
			'id="' + options['id'] + '"',
			'name="' + options['name'] + '"',
			'type="' + options['type'] + '"',
			'src="' + options['src'] + '"',
			'width="' + options['width'] + '"',
			'height="' + options['height'] + '"',
			'allowscriptaccess="' + options['allowscriptaccess'] + '"',
			'allowfullscreen="' + options['allowfullscreen'] + '"',
			'bgcolor="' + options['bgcolor'] + '"',
			'quality="' + options['quality'] + '"',
			'flashvars="' + flashvars + '"'
		];

		embed += attr.join(' ');
		embed += '></embed>';

		obj += embed;
		obj += '</object>';

		return obj;
	};

	/*
	 * Public methods
	 */
	this.set = function(key, value) {
		options[key] = value;
	};

	this.get = function(key) {
		return (typeof options[key] != 'undefined') ? options[key] : null ;
	};

	this.write = function() {
		var html = build();
		document.write(html);
	};

	this.html = function() {
		return build();
	};

};

