var UnreadMSG = Class.create({

	unread : null,
	
	req : null,
	
	initialize : function()
	{
		this.unread = $$("div.unread")[0];
		
		this.unread.writeAttribute("alt","Mensajes no leídos");
		$$("div.unreader").each(function(unr){ unr.writeAttribute("alt","Mensajes no leídos"); });
		
		this.req = new Ajax.PeriodicalUpdater(this.unread,"includes/php/web_request.php",{frequency: 5, parameters:{type:"total_unread_messages"}, onRequestComplete: function(retorno){
		if(SYS_isError(retorno.responseText))
		{
			SYS_doError(retorno.responseText);
			return;
		}		
		this.updateUnread();
		}.bind(this)});
	},
	
	updateUnread : function()
	{
		if(parseInt(this.unread.innerHTML) < 1) this.unread.hide();
		else this.unread.show();
		
		$$("div.unreader").each(function(unr)
		{
			unr.innerHTML = this.unread.innerHTML;
			if(parseInt(this.unread.innerHTML) < 1) unr.hide();
			else unr.show();
		}.bind(this));
	},
	
	cerrar : function()
	{
		if(this.req !== null) this.req.stop();
	}

});