var CommentOverlay = function (id) {
	this.overlay = new Overlay(id, {	width: '300px',
										draggable: true,
										visible: false,
										zindex: 1000,
										fixedcenter: true,
										constraintoviewport: true
	});

	// Metodo di connessione
	this.overlay.connectionMethod = 'POST';
	
	// Identifica un overlay a pił passi
	this.overlay.stepOverlay = true;
	
	this.show = function (anchorShow, text, anchorHide) {
		this.overlay.show(null, this.overlay.generateOverlay(text), null);
	};
	
	this.delete1 = function (commentId, postId){
		// Chiamata Ajax
		this.overlay.scriptUrl = 'http://' + location.hostname + '/overlay_manager/delete_comment';
		
		var actionString = 'comment_id=' + commentId + '&post_id=' + postId;
		this.overlay.setContentByAjax(actionString, null, null, this);
	};
	
	this.delete2 = function (commentId, postId){
		this.overlay.scriptUrl = 'http://' + location.hostname + '/gui_manager/delete_comment';
		
		this.show(null, '<center><img src="' + conf.staticUrl + '/js/widgets/overlay/img/ajax-loader.gif"></center>', null);
		var actionString = 'comment_id=' + commentId + '&post_id=' + postId;
		this.overlay.getResultByAjax(actionString, this, this.delete3);
	}
	
	this.delete3 = function (obj, data) {
		// cancellazione elemento
		var ul = YAHOO.util.Dom.get('ul_' + data['params']['postId']);
		var li = YAHOO.util.Dom.get('li_comment_' + data['params']['commentId']);
		new YAHOO.util.Element(ul).removeChild(li);
		
		// messaggio feedback
		var html = '<h3>' + data.header + '</h3>' +
					'<p>' + data.body + '</p>';
		
		obj.show(null, html, null);
		
		// aggiornamento contatore commenti
		document.getElementById('numComments_' + data['params']['postId']).value = Number(document.getElementById('numComments_' + data['params']['postId']).value) - 1;
		if(Number(document.getElementById('numComments_' + data['params']['postId']).value) == 0){
			document.getElementById('comments_counter_' + data['params']['postId']).innerHTML = 'commenta';
		}
		else{
			document.getElementById('comments_counter_' + data['params']['postId']).innerHTML = 'commenti (' + document.getElementById('numComments_' + data['params']['postId']).value + ')';
		}
	};
};