var SendOverlay = function (className) {
	this.overlay = new Overlay(className, {	width: '390px',
											draggable: true,
											visible: false,
											zindex: 1000,
											fixedcenter: true,
											constraintoviewport: true
	});

	// Identifica un overlay a pił passi
	this.overlay.stepOverlay = true;
	
	this.wrapper = function (overlay, args) {
		var params = {
			overlay: overlay,
			aaa_fn: args[2],
			t_nick: args[1],
			t_profile_id: args[0],
			t_gender: args[3],
			t_avatar: args[4],
			from: args[5]
		};
		
		// this.stepOne(overlay, args[0], args[1], { nick: args[2], pid: args[3], gender: args[4], avatar: args[5] });
		this.stepOne(params);
	};
	
	this.show = function (anchorShow, text, anchorHide) {
		this.overlay.show(null, this.overlay.generateOverlay(text), null);
	};
	
	// this.stepOne = function (overlay, stats, aaa_fn, receiver) {
	this.stepOne = function (params) {
		this.overlay.scriptUrl = "http://" + conf.baseUrl + "/overlay_manager/send_message";
		this.overlay.setContentByAjax(Utilities.createActionString(params), null, null, this);
	};
	
	this.stepTwo = function (formName) {
		this.overlay.scriptUrl = "http://" + conf.baseUrl + "/gui_manager/send_message";
		this.overlay.setContentByAjax('', null, null, this, formName, true);
	};
	
	this.reloadPage = function (t_pid) {
		var url = location.href.split('/');
		if(url[3] == 'message' && url[4] == 'outbox') {
			reload_ajax('http://' + conf.baseUrl + '/message/outbox?method=outbox', 'outbox', 'container message');
		} else if(url[3] == 'message' && url[4] == 'chronology') {
			reload_ajax('http://' + conf.baseUrl + '/message/chronology/' + t_pid + '/1?method=chronology', 'cronologia', 'container');
		}
	};
};

OverlayConfiguration.send = new SendOverlay('textOverlay');
OverlayManager.send = function (args) {
	OverlayConfiguration.send.wrapper('send', args);
};