function insertFlash_GV() {
	var rf = new RegExp('([0-9]+).*?([0-9]+).*?([0-9]+)', '');
	var desc = 'noflash';
	var bad = [0,0,0];
	if (navigator.plugins && navigator.plugins.length) {
		var pgs = navigator.plugins["Shockwave Flash"]
		if ( !pgs || !(desc = pgs.description) ) desc = 'noflash';
	} else {
		var app = navigator.appVersion.toUpperCase();
		if (app.indexOf("MSIE") >= 0 && app.indexOf("WIN") >= 0) {
			document.write(
				'<SCRIPT LANGUAGE="VBScript">\n' +
				'Function gIEfv()\n' +
				'on error resume next\n' +
				'Dim gotf, ctrl\n' +
				'set gotf = "noflash"\n' +
				'for i = 1 to 15\n' +
				' set ctrl = CreateObject("ShockwaveFlash.ShockwaveFlash." & CStr(i))\n' +
				' if (IsObject(ctrl)) then\n' +
				'  gotf = ctrl.GetVariable("$version")\n' +
				'  gIEfv = gotf\n' +
				'  exit for\n' +
				' end if\n' +
				'next\n' +
				'End Function\n' +
				'</SCRIPT>'
			);
			desc = gIEfv();
		}
	}
	if (desc == 'noflash') {
		insertFlash_Version = bad;
		return;
	}

	var w = rf.exec(desc);
	insertFlash_Version = (w == undefined) ? bad : w.slice(1);
	if (insertFlash_Version.length < 3) insertFlash_Version = bad;
}

function insertFlash_CV(req) {
	if (req == undefined || req.length == undefined || req.length < 3) return false;
	if (insertFlash_Version == undefined || insertFlash_Version.length == undefined || insertFlash_Version.length < 3) insertFlash_GV();
	for (var r,g,i = 0; i < 3; i++) {
		r = parseInt(req[i]);
		g = parseInt(insertFlash_Version[i]);
		if (r < g) return true;
		if (r > g) return false;
	}
	return true;
}

function insertFlash_Check(v1, v2, v3) {
	if (v1 == undefined || !(v1 = parseInt(v1))) return false;
	return insertFlash_CV([
		v1,
		v2 == undefined || !(v2 = parseInt(v2)) ? 0 : v2,
		v3 == undefined || !(v3 = parseInt(v3)) ? 0 : v3
	]);
}

function insertFlash(fo) {
	// ['name', 'where and how', default, {available values for enums}]
	// where and how: r - required, p - param, o - object, e - embed, s - string, d - dimentions, x - exception, n - enum, b - boolean, l - link
	var p = [
		['movie',		'rps'],
		['src',			'el',	'movie'],
		['id',			'ox',	'flashmovie'],
		['name',		'el',	'id'],
		['width',		'oed',	'100%'],
		['height',		'oed',	'100%'],
		['align',		'oen',	'', {l:1, r:1, t:1, b:1}],
		['version',		'x',	'6,0,0,0'],
		['play',		'peb',	'true'],
		['loop',		'peb',	'true'],
		['menu',		'peb',	'true'],
		['quality',		'pen',	'high', {low:1, medium:1, high:1, autolow:1, autohigh:1, best:1}],
		['scale',		'pen',	'showall', {showall:1, noscale:1, noborder:1, exactfit:1}],
		['salign',		'pen',	'', {l:1, r:1, t:1, b:1, tl:1, tr:1, bl:1, br:1, lt:1, rt:1, lb:1, rb:1}],
		['wmode',		'pen',	'window', {window:1, opaque:1, transparent:1, 'opaque windowless':1, 'transparent windowless':1}],
		['devicefont',		'peb',	'false'],
		['bgcolor',		'pex',	'#FFFFFF'],
		['allowscriptaccess',	'pen',	'samedomain', {always:1, never:1, samedomain:1}],
		['base',		'pes'],
		['FlashVars',		'pex'],
		['SeamlessTabbing',	'pb',	'true'],
		['swliveconnect',	'eb',	'false']
	];
	var _p = function(n,v) { return '<param name="' + n + '" value="' + v + '" />' };
	var _a = function(n,v) { return ' ' + n + '="' + v + '"' };
	var _i = function(l) { return 1 + wh.indexOf(l)};
	var _t = function() { return typeof fo[o]};

	var _s = 'string', _n = 'number', _o = 'object';

	var ri = new RegExp('([^\\\\/]+)\.swf', 'i');
	var rb = new RegExp('([0-9a-f]{6})$', 'i');
	var rv = new RegExp('^[0-9]+,[0-9]+,[0-9]+,[0-9]+$', '');
	var rp = new RegExp('^[0-9]+%?$', '');

	var i,o,wh;
	var ob = '<object', pb = '', eb = '<embed';

	if (typeof fo != _o) return alert('insertFlash Error: no options');
	for (i = 0; i < p.length; i++) {
		o = p[i][0];
		wh = p[i][1];
		if (_i('n')) { // Enum
			if (_t() != _s || p[i][3][fo[o].toLowerCase()] == undefined) fo[o] = p[i][2];
		} else if (_i('b')) { // Boolean
			if (_t() == _n) fo[o] = fo[o] ? 'true' : 'false';
			else if (_t() == _s) fo[o] = fo[o].toLowerCase() === 'true'? 'true' : fo[o].toLowerCase() === 'false'? 'false' : p[i][2];
			else if (_t() != 'boolean') fo[o] = p[i][2];
		} else if (_i('x')) { // Exceptions
			switch (o) {
				case 'id':
					if (_t() != _s) {
						var m = ri.exec(fo['movie']);
						if (m != undefined && typeof m[1] == _s) fo[o] = m[1];
						else fo[o] = p[i][2];
					}
					break;

				case 'bgcolor':
					if (_t() != _s) fo[o] = p[i][2];
					else {
						var m = rb.exec(fo[o]);
						if (m != undefined && typeof m[1] == _s) fo[o] = '#' + m[1];
						else fo[o] = p[i][2];
					}
					break;

				case 'version':
					if (_t() == _s) {
						if (!fo[o].match(rv)) fo[o] = p[i][2];
					} else if (_t() == _n) fo[o] = Math.floor(fo[o]) + ',0,0,0';
					else fo[o] = p[i][2];
					break;

				case 'FlashVars':
					if (_t() == _o) {
						var b = '';
						var fv = fo[o];
						var j = 0;
						for (var v in fv) b += (j++ ? '&' : '') + v + '=' + escape(fv[v]);
						fo[o] = j ? b : undefined;
					} else fo[o] = undefined;
					break;
			}
		} else if (_i('d')) { // dimentions
			if (_t() == _s) {
				if (!fo[o].match(rp)) fo[o] = p[i][2];
			} else if (_t() != _n) fo[o] = p[i][2];
		} else if (_i('s')) { // string
			if (_t() != _s) fo[o] = p[i][2];
		}

		if (fo[o] == undefined && _i('r')) return alert('insertFlash Error: bad "' + o + '"');
		if (_i('l')) fo[o] = fo[p[i][2]];

		if (fo[o] != undefined) {
			if (fo[o] != undefined) {
				if (_i('o')) ob += _a(o,fo[o]);
				if (_i('p')) pb += _p(o,fo[o]);
				if (_i('e')) eb += _a(o,fo[o]);
			}
		}
	}

	var ou =
		ob + ' classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' +
		fo['version'] + '">' + pb + eb +
		' type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>';

	if (typeof fo['alternative'] == _s) document.write(insertFlash_CV(fo['version'].split(',')) ? ou : fo['alternative']);
	else document.write(ou);

	if (typeof fo['focus'] != 'undefined' && fo['focus']) {
		var ft = window[fo['id']] ? window[fo['id']] : document['getElementById'] ? document.getElementById(fo['id']) : false;
		if (ft && typeof ft['focus'] != 'undefined') ft.focus();
	}
}

insertFlash_GV();
