// Author: Joseba Alonso
// Reference : http://www.sidedev.net/jsoop
// Version: 1.0
// LastChange: 30-5-2004

Object.registerClass = function(tag,_class,args){
	// Holds references to reapply the class mapping on document.createElement
	if(!this._tags)this._tags = new Array();
	// Fetch of the selected objects
	var tags;
	if(typeof tag == "string"){
		// No basic DOM, can't do anything with strings
		if(!document.getElementsByTagName || !document.getElementById){
			return false;
		}
		if(tag.charAt(0)!="#")this._tags[tag] = {_class:_class,args:args};
		if(!args)args = [];
		tags = (tag.charAt(0)=="#") ? [document.getElementById(tag.substr(1))] : document.getElementsByTagName(tag);
	}
	else{
		tags = [tag];
	}
	// Extending objects
	var obj;
	for(var i=0;i<tags.length;i++){
		obj = tags[i];
		// copy from prototype to the object
		for(var p in _class.prototype){
			obj[p] = _class.prototype[p];
		}
		// Reinstanciation
		if(_class.apply){
			_class.apply(obj,args);
		}
		else{
			// Old Browser- no apply, pollute
			obj.__RCinit = _class;
			obj.__RCinit(args[0],args[1],args[2],args[3],args[4],args[5],args[6],args[7],args[8],args[9]);
		}
	}
	return true;
}
// a createElement wrapper that reapplies the class to the new elements
// Maybe is better to create a custom method createClassElement?
document._createElement = document.createElement;
document.createElement = function(tag){
	var obj = this._createElement(tag);
	if(Object._tags[tag]){
		Object.registerClass(obj,Object._tags[tag]._class,Object._tags[tag].args);
	}
	return obj;
}