flashReplace = {
	requiredVersion: 8,   // Set for required flash version
	flashObjects: new Array(),
	installedVersion: 0,
	init: function() {
		if(navigator.plugins && navigator.mimeTypes.length){
			if(navigator.plugins["Shockwave Flash"] && navigator.plugins["Shockwave Flash"].description) flashReplace.installedVersion = navigator.plugins["Shockwave Flash"].description.replace(/([a-zA-Z]|\s)+/, "").split(".")[0];
		} else {
			flashReplace.installedVersion = new ActiveXObject("ShockwaveFlash.ShockwaveFlash").GetVariable("$version").split(" ")[1].split(",")[0];
		}
		if(flashReplace.installedVersion >= flashReplace.requiredVersion) flashReplace.replace();
	},
	add: function(element, swf, type) {
		flashReplace.flashObjects[flashReplace.flashObjects.length] = [element, swf, type];
	},
	rgb: function(red, green, blue) {   // Used for FireFox
		var hexChars = "0123456789ABCDEF";
		var hexColor = ""
		for (var i = 0; i < arguments.length; i++ ) {
			hexColor += hexChars.charAt((arguments[i] - arguments[i] % 16) / 16) + hexChars.charAt(arguments[i] % 16);
		}
    	return "#" + hexColor;
	},
	replace: function() {
		for(var i in flashReplace.flashObjects) {
			var swfNode;
			var swfId = flashReplace.flashObjects[i][0];
			var swf = flashReplace.flashObjects[i][1];
			var element = typeof(swfId) == "object" ? swfId : id(swfId);
			if(element) {
				var width = element.offsetWidth;
				var height = element.offsetHeight;
				if(flashReplace.flashObjects[i][2]) {   // Text replace
					// Get color style
					if (element.currentStyle) {
						var color = element.currentStyle["color"];
					} else if (document.defaultView && document.defaultView.getComputedStyle) {
						var color = document.defaultView.getComputedStyle(element,"").getPropertyValue("color");
					}
					if(color.indexOf("#") == -1) color = eval("flashReplace." + color);
					swf += "?txt=" + element.innerHTML + "&textcolor=" + color + "&w=" + width + "&h=" + height;
				}
				if(navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length && /gecko/.test(navigator.userAgent.toLowerCase())) { // Netscape, FireFox
					swfNode = document.createElement("embed");
					swfNode.setAttribute("type", "application/x-shockwave-flash");
					swfNode.setAttribute("src", swf);
					swfNode.setAttribute("width", width);
					swfNode.setAttribute("height", height);
					swfNode.setAttribute("id", "swf" + swfId);
					swfNode.setAttribute("name", "swf" + swfId);
					swfNode.setAttribute("wmode", "transparent");
					while(element.hasChildNodes()) {
						element.removeChild(element.firstChild);
					}
					element.appendChild(swfNode);
				} else { // IE, Opera
					swfNode = '<object id="swf' + swfId + '" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + width + '" height="' + height + '"><param name="movie" value="' + swf + '" /><param name="wmode" value="transparent" /></object>';
					element.innerHTML = swfNode;
				}
			}
		}
	}
}

// Replace all H3 tage with shelly-allegro swf
function replaceH3s() {
	var H3s = tag("h3");
	for(var i = 0; i < H3s.length; i++) {
		flashReplace.add(H3s[i], "shelly-allegro.swf", true);
	}
}

// Add DOMLoaded functions
addDOMLoadEvent(replaceH3s);
addDOMLoadEvent(flashReplace.init);