var flh = {
	flashVersion: function() {
		if(navigator.plugins && navigator.plugins['Shockwave Flash']) {
			var s = navigator.plugins['Shockwave Flash'].description;
			return parseInt(s.match(/\d+/));
		}
		if(window.ActiveXObject) {
			try {
				var s = new ActiveXObject('ShockwaveFlash.ShockwaveFlash');
				return parseInt(s.GetVariable('$version').match(/\d+/));
			} catch(e) {}
		}
		return 0;
	},
	getHTML: function(movie, width, height, params) {
		var html = 	[
			'<embed src="~movie~" width="~width~" height="~height~" ~fparams~'
			+ ' type="application/x-shockwave-flash"'
			+ ' pluginspage="http://www.adobe.com/go/getflashplayer" />'
			,
			'<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="~width~" height="~height~">'
			+ '<param name="movie" value="~movie~" />'
			+ '~fparams~'
			+ '</object>'
		];
		if(!movie.match(/\.swf\b/)) movie += ".swf";
		var useEmbed = navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length;
		var fparams = "";
		for(var p in params || {}) {
			if(useEmbed)
				fparams += p + '="' + params[p] + '" ';
			else
				fparams += '<param name="' + p + '" value="' + params[p] + '" />\n';
		}
		var h = useEmbed ? html[0] : html[1];
		return h.replace(/~(\w+)~/g, function($a, $b) { return eval($b); });
	},
	setHTML: function(elem, movie, width, height, params) {
		if(typeof(elem) == "string")
			elem = document.getElementById(elem);
		elem.innerHTML = flh.getHTML(movie, width, height, params);
	},
	writeHTML: function(movie, width, height, params) {
		document.write(flh.getHTML(movie, width, height, params));
	},
	fixHeight: function(element) {
		var hgt = element.offsetHeight;
		element.style.height = "100em";
		var ppe = element.offsetHeight / 100;
		var boxHeight = (hgt / ppe).toFixed(2);
		element.style.height  = boxHeight + "em";
		var c = 0;
		while(c++ < 1024 && element.offsetHeight > hgt) {
			boxHeight -= 0.01;
			element.style.height  = boxHeight + "em";
		}
	},	
	hexColor: function(c) {
		if(c.match(/^rgb/)) {
			var m = c.match(/\d+/g);
			c = (m[0] << 16) | (m[1] << 8) | (m[2]);
		}
		if(!c.toString().match(/^#/))
			c = "#" + (c | 0x1000000).toString(16).substr(1);
		return c;
	},
	replaceHTML: function(element, fontSwf, fgColor, bgColor) {
		if(flh.flashVersion() < 7) 
			return;
		fgColor = flh.hexColor(fgColor || 0);
		bgColor = flh.hexColor(bgColor || 0);
		var vars = [
			"text=" + encodeURIComponent(element.innerHTML),
			"fgColor=" + fgColor,
			"bgColor=" + bgColor
		];
		var p = {
			flashVars: vars.join("&"),
			align: "left",
			quality: "high",
			salign: "lt",
			bgcolor: bgColor,
			wmode: "opaque"
		}
		var h = flh.getHTML(fontSwf, "100%", "100%", p);
		return h;
	}
}
