function _extensionsInit(){
	Extensions.init();
}
window.addEvent("load",_extensionsInit);

Extensions = {
	emptyTags: {
	   "IMG":   true,
	   "BR":    true,
	   "INPUT": true,
	   "META":  true,
	   "LINK":  true,
	   "PARAM": true,
	   "HR":    true
	},
	
	prebuiltId: "prebuilt_extensions",
	contextPath: "",
	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;
			}
		}
	},
	
	// add classes (space delimited) to elements to add extension properties
	/*extensions: [{className:"clearOnFocus",prop:"onfocus",value:"if(this.firstTime!=true){this.firstTime = true;this.value = '';}"}],
	
	addExtensions: function(){
		for(var i=0; i<this.extensions.length; i++){
			var ext = this.extensions[i];
			var items = $$('.'+ext.className);
			for(var x=0; x<items.length; x++){
				$(items[x]).setProperty(ext.prop,ext.value);
				items[x][ext.prop] = ext.value;
			}
		}
	},*/
	divsChanged: function(){
		//this.addExtensions();
		if(navigator.appName.indexOf("Microsoft") != -1) {
			/* IE 6 and IE 7 have problems rendering SIFR elements if the page is scrolled (or something)
			 * and calling the following methods later fixes the problem.
			 */
			var me = this;
			setTimeout(function() {
				me.replaceTags();
				me.doSIFR();
				}, 1);
		} else {
			this.replaceTags();
			this.doSIFR();
		}
	},
	
	// add ret attributes to elements to add Classes
	tags: {Scale9Grid:Scale9Grid,
			Scale9Button:Scale9Button},
	divAttributes: ["id","class","style","onclick"],
	replaceTags: function(){
		for(var i in this.tags){
			var classRef = this.tags[i];
			var items = $$('.'+i);
			for(var x=0; x<items.length; x++){
				var item = items[x];
				item.removeClass(i);
				var replacement = new classRef();
				
				for(var y=0; y<this.divAttributes.length; y++){
					var name = this.divAttributes[y];
					var prop = item.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);
						}
					}
				}
				replacement.setHTML(item.innerHTML);
				replacement.injectAfter(item);
				item.remove();
			}
		}
	},
	doSIFR: function(){
		if(typeof sIFR == "function"){
			sIFR.replaceElement("div.whiteTitle", this.contextPath + "style/fonts/cooperblack.swf", named({sBgColor:"#ffffff", sColor:"#FF0000", sWmode:"transparent"}));
			sIFR.replaceElement("div.loginNameLabel", this.contextPath + "style/fonts/vagrounded.swf", named({sBgColor:"#ffffff", sColor:"#0098bc", sWmode:"transparent"}));
		};		
	}
};