var refreshModuleClass = stdClass.extend({
	//constructor
	constructor: function(settings) {
		this.base();
		// initialize settings
		Object.extend(this.s, {
			moduleName: 'RefreshModule',
			ceid: null,
			json: {
				ver: '0.1',
				meta: {},
				data: {},
				requests: []
			}
			/* put extensions to settings here */
		});
		Object.extend(this.s, settings);
		
		// initialize nodes
		Object.extend(this.n, {
			/* put extensions to nodes here */
		});
		
		// initialize collections
		Object.extend(this.c, {
			requests: []
			/* put extensions to collections here */
		});
	},
	
	refresh: function(moduleNames){
		
		for(var x=0; x<moduleNames.length; x++){
			this.addRequest('getModule', {
				moduleName: moduleNames[x]
			});
		}
		this.JsonOut();
	},
	
	addRequest: function(requestName, dataObject) {
		this.c.requests.push({
			id: this.c.requests.length,
			type: requestName,
			data: dataObject
		});
	},
	//json methods
	JsonOut: function() {
		//construct the post
		this.s.json.data.requests = this.c.requests;
		//this.setMeta('columns', '');
		var data = '__json=' + this.s.moduleName + '&data=' + toJSONString(this.s.json);
		this.c.requests = [];
		//send out the request
		var myAjax = new Ajax.Request(window.location,
		{
			method: 'post',
			parameters: data,
			onSuccess: this.JsonIn.bind(this)
		});
	},
	
	JsonIn: function(t) {
		var result = t.responseText.parseJSON();
		(result.responses.length).times(function(i) {
			switch(result.responses[i].type){
			case "showPageModule":
				var tempEl = document.createElement('div');
				tempEl.innerHTML = result.responses[i].data.html;
				var ele = document.getElementById('pmid_' + result.responses[i].data.pageModuleId);
				if(ele){
					ele.innerHTML = document.getElementsBySelector('.module', tempEl)[0].innerHTML;
					if(typeof(addComment) != 'undefined'){
						var addComments = document.getElementsBySelector('a.comment', ele);
						for(var x=0; x<addComments.length; x++){
							new addComment(addComments[x]);
						}
					}
				}
				break;
			}
		}.bind(this));
	}
});

var RefreshModule = new refreshModuleClass({});