RemoteConfig = new u.Class({
	__construct:function(params) {
		this.url = params[0];
		this.moduleStr = params[1];
		return this;
	}
});

RemoteConnector = new u.Class({
	remoteConfig:null,
	className:null,
	importClass:function(className) {
		var data = {};
		data[this.remoteConfig.moduleStr] = className;
		
		this.responseData = u.post(
			this.remoteConfig.url,
			data,
			false).text;			
			
		var responseObject = eval('('+this.responseData+')');
	
		for(var module in responseObject) {
			this[module] = responseObject[module];
			this[module].parent = this;
				
			this.parseAttributes(module);
			
			this.parseMethods(module);

		}
		
	},
	parseAttributes:function(moduleName) {
		for(var attribute in this[moduleName].attributes)
		this[moduleName][attribute] = this[moduleName].attributes[attribute];
	},
	parseMethods:function(moduleName) {

		for(var i=0,l=this[moduleName].methods.length;i<l;i++) {
			var methodName = this[moduleName].methods[i];
			
			string = 'this.'+moduleName+'.'+methodName+' = function() {\n'+
				'this.call = {};\n'+
				'this.call.callString = "'+moduleName+'.'+methodName+'";\n'+
				'this.call.params = arguments[0];\n'+
				'this.call.attributes = this.attributes;\n'+
				'return eval("("+u.post(this.parent.remoteConfig.url,{jrc:JSON.stringify(this.call)},false).text+")");\n'+
			'}';
			try {
				eval("(" + string + ")");
			} catch(ex) {
				
			}
		}
		
	},
	setRemoteConfig:function(remoteConfig) { // Param => Instance of RemoteConfig
		this.remoteConfig = remoteConfig;
	}
});
