function _extensionsInit(){
	Extensions.init();
}
window.addEvent("domready",_extensionsInit);

Extensions = {
	// add class attributes to elements to add Classes (space delimited)
	tags: {},
	// these are attributes that will be transferred to new classes.
	divAttributes: ["id","class","style","onclick","ret","tabindex"],
	
	emptyTags: {
	   "IMG":   true,
	   "BR":    true,
	   "INPUT": true,
	   "META":  true,
	   "LINK":  true,
	   "PARAM": true,
	   "HR":    true
	},
	
	prebuiltId: "prebuilt_extensions",
	inited: false,
	
	init: function(){
		if(!this.inited){
			this.inited = true;
			this.prebuilts = $(this.prebuiltId);
			if(this.prebuilts){
				this.prebuilts.remove();
			}
			
			this.divsChanged();
			if(navigator.appName.indexOf("Microsoft") == -1)this.mozillaOuterHTML();
			EventDispatcher.implement(this);
		}
	},
	mozillaOuterHTML: function(){
		HTMLElement.prototype.__defineGetter__("outerHTML", function () {
		   var attrs = this.attributes;
		   var str = "<" + this.tagName;
		   for (var i = 0; i < attrs.length; i++)
			  str += " " + attrs[i].name + "=\"" + attrs[i].value + "\"";
		
		   if (Extensions.emptyTags[this.tagName])return str + "/>";
		
		   return str + ">" + this.innerHTML + "</" + this.tagName + ">";
		});
	},
	getPrebuilt: function(id){
		this.init();
		var div = this.findChild(this.prebuilts, id);
		return div;
	},
	findChild: function(within, id){
		var children = within.getChildren();
		for(var i=0; i<children.length; i++){
			var child = children[i];
			if(child.getProperty("id")==id){
				return child
			}else{
				var child2 = this.findChild(child, id);
				if(child2)return child2;
			}
		}
	},
	divsChanged: function(){
		this.replaceTags();
	},
	addReplacableTag: function(name, classRef){
		if(name){
			if(!this.tags)this.tags = {};
			this.tags[name] = classRef;
			if(this.inited)this.replaceTags();
		}
	},
	replaceTags: function(){
		for(var i in this.tags){
			var items = $$('.'+i);
			for(var x=0; x<items.length; x++){
				Extensions.replaceTag(items[x],i);
			}
		}
	},
	replaceTag: function(element, className){
		var classRef = this.tags[className];
		try{
			if(!classRef)classRef = eval(className);
		}catch(e){}
		element.removeClass(className);
		var replacement;
		if(classRef){
			replacement = new classRef();
			for(var y=0; y<this.divAttributes.length; y++){
				var name = this.divAttributes[y];
				var prop = element.getProperty(name);
				if(prop){
					if(name=="style" && window.ie){
						for(var j in prop){
							if(prop[j] && j!="cssText"){
								replacement.setStyle(j,prop[j])
							}
						}
					}else{
						replacement.setProperty(name,prop);
					}
				}
			}
			if(!replacement.events){
				replacement.events = {};
			}
			replacement.setHTML(element.innerHTML);
			replacement.injectBefore(element);
		}
		element.remove();
		return replacement;
	}
};
