var Replacer = {

	/**
	* Method for replacing an element with an image
	*/
	imageReplace:function(removeId,replaceImg,altText){
		var removeNode = document.getElementById(removeId);
		var parent = removeNode.parentNode;
		var newNode = removeNode.cloneNode(false);
		var img = document.createElement("img");
		img.setAttribute('alt',altText ? altText : "");
		img.setAttribute('src',replaceImg);
		newNode.appendChild(img);
		parent.replaceChild(newNode,removeNode);
		return true;
	},
	
	/**
	* Method for replacing an element with an swf
	* optionally sending in the content as a data of the element as a data source
	* Here's an example swf object
	* http://blog.deconcept.com/swfobject/#examples
	* <script type="text/javascript">
	* var so = new SWFObject("movie.swf", "mymovie", "400", "100%", "8", "#336699");
	* so.addParam("quality", "low");
	* so.addParam("wmode", "transparent");
	* so.addParam("salign", "t");
	* so.write("flashcontent");
	* </script>
	* @param The id of the element to replace
	* @param The swfobject to embed the movie
	* @param The variable to send into the movie optional
	*/
	swfObjectReplace:function(removeId,swfObject,varName){
		var removeNode = document.getElementById(removeId);
		var parent = removeNode.parentNode;
		var newNode = removeNode.cloneNode(false);
		if(varName){
			swfObject.addVariable(varName, encodeURIComponent(this.htmlToXML(removeNode)));
		}						

		//newNode.innerHTML = swfObject.getSWFHTML();
		var success = swfObject.write(newNode);
		if(success){
			parent.replaceChild(newNode,removeNode);
		}
		return success;
	},
	
	htmlToXML:function(node){
		var str = "";
		if(node.nodeType == 1){
			str+="<"+node.nodeName;
			if(node.attributes.length > 0){
				for(var i = 0; i < node.attributes.length; i++){
					var a = node.attributes[i];
					//IE has a bazillion attributes, filter them out as much as possible
					if(a.nodeValue != null && typeof a.nodeValue == "string" && a.nodeValue != "" && a.nodeName != "contentEditable"){
						str+=" "+a.nodeName+"=\""+a.nodeValue+"\"";
					}
				}
			}
			if(node.childNodes.length > 0){
				str+=" >";
				for(var j = 0; j < node.childNodes.length; j++){
					str+=this.htmlToXML(node.childNodes[j]);
				}
				str+="</"+node.nodeName+">";
			}else{
				str+=" />";
			}
		}else if(node.nodeType == 3){
			str+=node.nodeValue;
		}
		return str;
	}
	
};