Index: /trunk/instant_messenger/setup/phpgw_pt-br.lang
===================================================================
--- /trunk/instant_messenger/setup/phpgw_pt-br.lang	(revision 305)
+++ /trunk/instant_messenger/setup/phpgw_pt-br.lang	(revision 311)
@@ -4,6 +4,8 @@
 add new contact	instant_messenger	pt-br	Adicionar Novo Contato
 add user	instant_messenger	pt-br	Adicionar Usuário
+allow	instant_messenger	pt-br	Adicionar
 Added information!	instant_messenger	pt-br	Informações Adicionadas!
 Authorization	instant_messenger	pt-br	Autorização
+available	instant_messenger	pt-br	Conectado
 away	instant_messenger	pt-br	Ausente
 Birthday	instant_messenger	pt-br	Aniversário
@@ -19,4 +21,6 @@
 Delete	instant_messenger	pt-br	Remover
 Description	instant_messenger	pt-br	Descrição
+dnd	instant_messenger	pt-br	Desconectado
+deny	instant_messenger	pt-br	Negar
 Error in the message!	instant_messenger	pt-br	Erro na mensagem!
 E-mail	instant_messenger	pt-br	E-mail
@@ -32,4 +36,5 @@
 List of Contacts	instant_messenger	pt-br	Lista de Contatos
 Loading...	instant_messenger	pt-br	Carregando...
+member of organization	instant_messenger	pt-br	Usuários da Organização
 Maximize/Restore	instant_messenger	pt-br	Maximizar/Restaurar Janela
 Minimize	instant_messenger	pt-br	Minimizar Janela
@@ -74,4 +79,5 @@
 Update	instant_messenger	pt-br	Atualizar
 Username	instant_messenger	pt-br	Username
+unavailable	instant_messenger	pt-br	Não Perturbe
 Vcard	instant_messenger	pt-br	Vcard
 You desire to register in service IM?	instant_messenger	pt-br	Você deseja registrar no serviço IM?
Index: /trunk/instant_messenger/xsl/contacts.xsl
===================================================================
--- /trunk/instant_messenger/xsl/contacts.xsl	(revision 305)
+++ /trunk/instant_messenger/xsl/contacts.xsl	(revision 311)
@@ -15,6 +15,7 @@
 				<xsl:choose>
 					<xsl:when test="not(group = preceding-sibling::item/group)">
-						<img id="group_{group[current()]}" src="{$path}templates/default/images/group_open.gif" onclick="javascript:im.group_close('{group[current()]}');"/>
-						<b><xsl:value-of select="group[current()]" /><br/></b>
+						<div style="font-weight:bold;padding-left:16px;background:url({$path}templates/default/images/group_open.gif) no-repeat;">
+							<xsl:value-of select="group[current()]" />
+						</div>
 						<xsl:apply-templates select="." mode="contacts"/>
 					</xsl:when>
Index: /trunk/instant_messenger/xsl/window.xsl
===================================================================
--- /trunk/instant_messenger/xsl/window.xsl	(revision 305)
+++ /trunk/instant_messenger/xsl/window.xsl	(revision 311)
@@ -12,5 +12,6 @@
 		</b>
 		<div class="titulo">
-			<span id="{name}__window_title" style="float:left;"></span>
+			<div class="icon"></div>
+			<span id="{name}__window_title" style=""></span>
 			<div id="{name}__window_title_buttons" class="buttons">
 				<div title="close" class="button_close"></div>
Index: /trunk/instant_messenger/inc/Jabberd2.abstract.php
===================================================================
--- /trunk/instant_messenger/inc/Jabberd2.abstract.php	(revision 305)
+++ /trunk/instant_messenger/inc/Jabberd2.abstract.php	(revision 311)
@@ -171,4 +171,11 @@
 	}
 
+	final function get_last_access_user($pUser)
+	{
+		$id = "last_time_user";
+		$jid = ( trim($pUser['jid']) == "this" ) ? $this->_user . '@' . $this->_server : $pUser['jid'];
+		$this->iq('get', $id, $jid, NULL, "jabber:iq:last");
+	}
+
 	final function setStatus()
 	{
Index: /trunk/instant_messenger/inc/class.Ujabber.inc.php
===================================================================
--- /trunk/instant_messenger/inc/class.Ujabber.inc.php	(revision 305)
+++ /trunk/instant_messenger/inc/class.Ujabber.inc.php	(revision 311)
@@ -74,4 +74,6 @@
 			return "disconnected";
 
+		$this->get_last_access_user(array("jid" => "this"));
+
 		if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') )
 		{
@@ -89,5 +91,5 @@
 			$buffer = '';
 
-			while ( ( connection_aborted() === 0 ) && time() - $init < 50 )
+			while ( ( connection_aborted() === 0 ) && time() - $init < 30 )
 			{
 				# read from server and write in the client
Index: /trunk/instant_messenger/js/images.js
===================================================================
--- /trunk/instant_messenger/js/images.js	(revision 305)
+++ /trunk/instant_messenger/js/images.js	(revision 311)
@@ -29,4 +29,7 @@
 	var im_group_open = new Image();
 	im_group_open.src = path_im + 'templates/default/images/group_open.gif';
+
+	var im_group_close = new Image();
+	im_group_close.src = path_im + 'templates/default/images/group_close.gif';
 
 // Smiles
Index: /trunk/instant_messenger/js/jabber.js
===================================================================
--- /trunk/instant_messenger/js/jabber.js	(revision 305)
+++ /trunk/instant_messenger/js/jabber.js	(revision 311)
@@ -5,6 +5,5 @@
 	var _window;
 	var _ldap;
-
-	var _menu = new ShowHidden(1500);
+	var _menu;
 
 	var _vcards = [];
@@ -138,5 +137,9 @@
 		var _win = _window.get('chat' + id);
 		if ( !_win )
-			_chat(id);
+		{
+			_win = _chat(id);
+			var _st = el.style.backgroundImage;
+			_win.icon(_st.substr(4, (_st.length - 5)));
+		}
 		else
 		{
@@ -155,4 +158,5 @@
 			_win_contact.bc.style.display = 'none';
 			_win_contact.wm.style.display = 'none';
+			_win_contact.icon(im_available.src);
 
 		var _params = {
@@ -172,5 +176,6 @@
 		if ( _contact_list )
 		{
-			_conn.go('$this.Ujabber.setStatus');
+			_setPresence('unavailable');
+			_setPresence();
 			_ldap.photo(
 				'im_avatar',
@@ -222,5 +227,6 @@
 					var _sub_menu = top.document.getElementById('sub_' + el.getAttribute('jid'));
 						_sub_menu.innerHTML = _xtools.parse(_xml, 'options.xsl');
-						_menu.action('onmouseover', 'onmouseout', _sub_menu);
+
+					_menu.action('onmouseover', 'onmouseout', _sub_menu);
 
 					_sub_menu = _sub_menu.firstChild;
@@ -260,10 +266,33 @@
 			while ( _contact )
 			{
+				_config(_contact, 'onmouseover', _hover);
+				_config(_contact, 'onmouseout', _hover);
 				if ( _contact.getAttribute('jid') )
 				{
 					//_config(_contact, 'onmousedown', _click);
 					_config(_contact, 'onmouseup', _click);
-					_config(_contact, 'onmouseover', _hover);
-					_config(_contact, 'onmouseout', _hover);
+				}
+				else
+				{
+					_config(_contact, 'onclick',
+					function(e)
+					{
+						var el = ( e.target ) ? e.target : e.srcElement;
+
+						if ( el.style.backgroundImage.indexOf('group_open') < 0 )
+							el.style.backgroundImage = 'url(' + im_group_open.src + ')';
+						else
+							el.style.backgroundImage = 'url(' + im_group_close.src + ')';
+
+						el = el.nextSibling;
+						while ( el.getAttribute('jid') )
+						{
+							el.style.display = ( el.style.display != 'none' ) ?
+								'none' : 'block';
+							el = el.nextSibling;
+							if ( el && el.nextSibling )
+								el = el.nextSibling;
+						}
+					});
 				}
 				_contact = _contact.nextSibling;
@@ -272,4 +301,34 @@
 	}
 
+	function _setPresence()
+	{
+		var _presence = false;
+		var _pPresence;
+		if ( arguments.length == 0 )
+			_pPresence = 'available';
+		else
+			_pPresence = arguments[0];
+		switch ( _pPresence )
+		{
+			case 'away':
+			case 'dnd':
+			case 'xa':
+				_presence = 'show=' + _pPresence;
+			break;
+			case 'available':
+			case 'unavailable':
+				_presence = 'type=' + _pPresence;
+			break;
+		}
+
+		if ( _presence )
+		{
+			var _status = top.document.getElementById('im_status');
+			if ( _status )
+				_status.style.backgroundImage = 'url(' + eval('im_' + _pPresence + '.src') + ')';
+			_conn.go('$this.Ujabber.setPresence', _presence);
+		}
+	}
+
 	function _vcard(_pJid)
 	{
@@ -285,5 +344,5 @@
 
 				_win_vcard = _window.load('vcard_' + _pJid);
-				_win_vcard.title('.:: InformaÃ§Ãµes do Contato ::.');
+				_win_vcard.title('.:: Informações do Contato ::.');
 				_win_vcard.size(300);
 				_win_vcard.position(_win_pos, _win_pos);
@@ -347,6 +406,15 @@
 				_readVCard(pIq);
 			break;
+			case 'last_time_user' :
+				_readLastTimeUser(pIq);
+			break;
 			default : //alert('readIq : ' + pIq.getAttribute('id'));
 		}
+	}
+
+	function _readLastTimeUser(pIq)
+	{
+		if ( pIq.firstChild.getAttribute("seconds") != 0 )
+			_setPresence();
 	}
 
@@ -366,5 +434,13 @@
 		{
 			if ( !_win )
+			{
 				_win = _chat(_from);
+				var _st = top.document.getElementById('contact_' + _from);
+				if ( _st )
+				{
+					_st = _st.style.backgroundImage;
+					_win.icon(_st.substr(4, (_st.length - 5)));
+				}
+			}
 
 			var _history = _win.wc.firstChild;
@@ -409,4 +485,6 @@
 		var _img_status_contact = top.document.getElementById('contact_' + _from);
 		var _mensagem_status_contact = top.document.getElementById('status_' + _from);
+		var _win_chat = _window.get('chat' + _from);
+
 		if ( _mensagem_status_contact )
 		{
@@ -423,4 +501,6 @@
 					if ( _img_status_contact )
 						_img_status_contact.style.backgroundImage = 'url(' + eval('im_' + _presence_type + '.src') + ')';
+					if ( _win_chat )
+						_win_chat.icon(eval('im_' + _presence_type + '.src'));
 				break;
 				case 'subscribe' :
@@ -538,4 +618,6 @@
 							if ( _img_status_contact )
 								_img_status_contact.style.backgroundImage = 'url(' + eval('im_' + _node.firstChild.nodeValue + '.src') + ')';
+							if ( _win_chat )
+								_win_chat.icon(eval('im_' + _node.firstChild.nodeValue + '.src'));
 						break;
 						case "status" :
@@ -550,4 +632,6 @@
 							if ( _img_status_contact )
 								_img_status_contact.style.backgroundImage = 'url(' + im_available.src + ')';
+							if ( _win_chat )
+								_win_chat.icon(im_available.src);
 					}
 				}
@@ -610,7 +694,9 @@
 		_window = arguments[2];
 		_ldap = arguments[3];
+		_menu = arguments[4];
 	}
 
 	Jabber.prototype.action = _action;
+	Jabber.prototype.setPresence = _setPresence;
 	window.Jabber = Jabber;
 }
Index: /trunk/instant_messenger/js/connector.js
===================================================================
--- /trunk/instant_messenger/js/connector.js	(revision 305)
+++ /trunk/instant_messenger/js/connector.js	(revision 311)
@@ -181,6 +181,6 @@
 			return {'error' : "#1\n\n" + usage()};
 
-		if ( _THREADS[_ID] )
-			return {'error' : '#2 - there is a equal request running'};
+		//if ( _THREADS[_ID] )
+		//	return {'error' : '#2 - there is a equal request running'};
 
 		_THREADS[_ID] = {
Index: /trunk/instant_messenger/js/windows.js
===================================================================
--- /trunk/instant_messenger/js/windows.js	(revision 305)
+++ /trunk/instant_messenger/js/windows.js	(revision 311)
@@ -40,15 +40,16 @@
 			_window.childNodes[1].childNodes[1].setAttribute('dragdrop_child','true');
 
-			_config(_window.childNodes[1].childNodes[1].childNodes[0], 'onclick', _button);
-			_config(_window.childNodes[1].childNodes[1].childNodes[1], 'onclick', _button);
-			_config(_window.childNodes[1].childNodes[1].childNodes[2], 'onclick', _button);
+			_config(_window.childNodes[1].childNodes[2].childNodes[0], 'onclick', _button);
+			_config(_window.childNodes[1].childNodes[2].childNodes[1], 'onclick', _button);
+			_config(_window.childNodes[1].childNodes[2].childNodes[2], 'onclick', _button);
 
 			_all_windows[pId + '__window_master'] = {
 				'id' : pId,
 				'wm' : _window, // wm - window master
-				'wt' : _window.childNodes[1].firstChild, // wt - window title
-				'bc' : _window.childNodes[1].childNodes[1].childNodes[0], // bc - button close
-				'bx' : _window.childNodes[1].childNodes[1].childNodes[1], // bx - button maximize
-				'bz' : _window.childNodes[1].childNodes[1].childNodes[2], // bz - button minimize
+				'ic' : _window.childNodes[1].firstChild, // wt - window title
+				'wt' : _window.childNodes[1].childNodes[1], // wt - window title
+				'bc' : _window.childNodes[1].childNodes[2].childNodes[0], // bc - button close
+				'bx' : _window.childNodes[1].childNodes[2].childNodes[1], // bx - button maximize
+				'bz' : _window.childNodes[1].childNodes[2].childNodes[2], // bz - button minimize
 				'wc' : _window.childNodes[2].firstChild, // wc - window content
 				'wf' : _window.childNodes[3], // wf - window footer
@@ -56,4 +57,5 @@
 				'content' : _content,
 				'focus' : _focus,
+				'icon' : _icon,
 				'position' : _position,
 				'size' : _size,
@@ -240,4 +242,10 @@
 	}
 
+	function _icon(_pIcon)
+	{
+		if ( typeof _pIcon == 'string' )
+			this.ic.style.backgroundImage = 'url(' + _pIcon + ')';
+	}
+
 	function _position(pX, pY)
 	{
Index: /trunk/instant_messenger/js/client.js
===================================================================
--- /trunk/instant_messenger/js/client.js	(revision 305)
+++ /trunk/instant_messenger/js/client.js	(revision 311)
@@ -29,8 +29,9 @@
 	var _window = new Windows(_xtools, _im_content);
 	var _ldap = new InstantMessengerLDAP(_conn, _xtools, _window);
-	var _jabber = new Jabber(_conn, _xtools, _window, _ldap);
+	var _showhidden = new ShowHidden(1500);
+	var _jabber = new Jabber(_conn, _xtools, _window, _ldap, _showhidden);
 
 	// XSL preload
-	var _xsl_preload = ['chat.xsl','layer.xsl','contacts'];
+	var _xsl_preload = ['window.xsl','layer.xsl','contacts.xsl', 'chat.xsl'];
 	var _xsl_preload_legth = _xsl_preload.length;
 	for ( var i = 0; i < _xsl_preload_legth; i++ )
@@ -40,8 +41,16 @@
 	if ( (local = top.document.getElementById('user_info')) )
 	{
-		local.innerHTML = ' ' + local.innerHTML;
-		var _status = top.document.createElement('img');
-			_status.setAttribute('id','im_status_src');
-			_status.src = im_available.src;
+		local.firstChild.style.marginLeft = '30px';
+
+		var _status = top.document.createElement('div');
+			_status.setAttribute('id', 'im_status');
+			_status.style.height = '15px';
+			_status.style.margin = '0 0 0 10px';
+			_status.style.padding = '0px';
+			_status.style.width = '15px';
+			_status.style.background = 'no-repeat';
+			_status.style.backgroundImage = 'url(' + im_unavailable.src + ')';
+			_status.style.float = 'left';
+			_status.style.position = 'absolute';
 
 		local.insertBefore(_status, local.firstChild);
@@ -50,17 +59,88 @@
 
 		var _menu;
-		_menu = top.document.createElement('span');
-		_menu.setAttribute('id','fast_menu_im');
+			_menu = top.document.createElement('span');
+			_menu.setAttribute('id','fast_menu_im');
+			_menu.style.backgroundColor = 'b4cfe5';
+			_menu.style.display = 'none';
+			_menu.style.margin = '15px 0 0 -15px';
+			_menu.style.position = 'absolute';
+			_menu.style.zIndex = '99999';
 		local.insertBefore(_menu, local.firstChild);
 
-		_menu = top.document.createElement('img');
-		_menu.src = im_fast_menu.src;
-		local.insertBefore(_menu, local.firstChild);
-
-		//var local_old = local.innerHTML ;
-		//local.innerHTML  = '<img src="' + im_fast_menu.src + '" onclick="javascript:templates.fast_menu();">';
-		//local.innerHTML += '<img id="im_status_src" src="' + im_available.src + '" onclick="javascript:load_im_contacts();"/>';
-		//local.innerHTML += local_old;
-		//local.innerHTML += '<div id="instant_messenger_content"></div><span id="fast_menu_im"/>';
+		var _menu_img = top.document.createElement('div');
+			_menu_img.style.background = 'no-repeat';
+			_menu_img.style.backgroundImage = 'url(' + im_fast_menu.src + ')';
+			_menu_img.style.height = '10px';
+			_menu_img.style.margin = '0px';
+			_menu_img.style.padding = '0px';
+			_menu_img.style.position = 'absolute';
+			_menu_img.style.width = '10px';
+			_menu_img.style.float = 'left';
+		local.insertBefore(_menu_img, local.firstChild);
+
+		_config(
+			_menu_img,
+			'onclick',
+			function()
+			{
+				var _options = [
+					'available',
+					'away',
+					'dnd',
+					'unavailable'
+				];
+
+				var _style_text = 'cursor: pointer; padding:2px 4px 2px 20px; background: no-repeat ';
+
+				var _xml = _xtools.xml('menu');
+				var _option;
+				var _item;
+				var _action;
+				var _style;
+
+				for ( var i in _options )
+				{
+					_option = _xml.createElement('option');
+
+					_item = _xml.createElement('item');
+					_item.appendChild(_xml.createTextNode(imGetLang(_options[i])));
+
+					_style = _xml.createElement('style');
+					_style.appendChild(_xml.createTextNode(_style_text + 'url(' + eval('im_' + _options[i] + '.src') + ')'));
+
+					_option.appendChild(_item);
+					_option.appendChild(_style);
+
+					_xml.documentElement.appendChild(_option);
+				}
+
+				_menu.innerHTML = _xtools.parse(_xml, 'options.xsl');
+				_showhidden.action('onmouseover', 'onmouseout', _menu);
+
+				_item = _menu.firstChild;
+
+				for ( var i in _options )
+				{
+					_item.childNodes[i].setAttribute('presence', _options[i]);
+					_config(
+						_item.childNodes[i],
+						'onclick',
+						function(e)
+						{
+							var el = ( e.target ) ? e.target : e.srcElement;
+
+							_status.style.backgroundImage = el.style.backgroundImage;
+
+							var _presence = el.getAttribute('presence');
+								_jabber.setPresence(_presence);
+
+							var _win_contacts = _window.get('contact_list');
+							if ( _win_contacts )
+								_win_contacts.icon(eval('im_' + _presence + '.src'));
+						}
+					);
+				}
+			}
+		);
 	}
 
@@ -114,4 +194,5 @@
 	}
 
+	var _count_reconnect = 0;
 	function _request()
 	{
@@ -122,4 +203,6 @@
 				'classCostructor=read'
 			);
+		else
+			setTimeout(_reconnect, (++_count_reconnect * 2000));
 	}
 
Index: /trunk/instant_messenger/js/ldap.js
===================================================================
--- /trunk/instant_messenger/js/ldap.js	(revision 305)
+++ /trunk/instant_messenger/js/ldap.js	(revision 311)
@@ -51,6 +51,6 @@
 					if ( !_jid )
 					{
-						_status.innerHTML = 'Selecione uma organizaÃ§Ã£o no campo da esquerda e em<br/>'
-											+ ' seguida, no campo da direita, um membro da organizaÃ§Ã£o<br/>'
+						_status.innerHTML = 'Selecione uma organização no campo da esquerda e em<br/>'
+											+ ' seguida, no campo da direita, um membro da organização<br/>'
 											+ ' para adicionar como contato';
 					}
@@ -62,5 +62,5 @@
 						if ( !(_name.value) || !(_group.value) )
 						{
-							_status.innerHTML = '<br/>O campo destacado em vermelho Ã© obrigatÃ³rio!<br/>';
+							_status.innerHTML = '<br/>O campo destacado em vermelho é obrigatório!<br/>';
 
 							if ( !(_name.value) )
Index: /trunk/instant_messenger/templates/default/css/window.css
===================================================================
--- /trunk/instant_messenger/templates/default/css/window.css	(revision 305)
+++ /trunk/instant_messenger/templates/default/css/window.css	(revision 311)
@@ -21,4 +21,11 @@
 }
 
+#instant_messenger_content .icon
+{
+	position:absolute !important;
+	height: 15px;
+	width: 15px;
+}
+
 #instant_messenger_content .titulo
 {
@@ -27,7 +34,14 @@
 	font: 8pt Verdana, Arial, Helvetica, sans-serif;
 	height: 20px;
-	margin: 0px 0px;
-	padding: 0px 0px 0px 5px;
+	line-height: 1.5em;
+	margin: 0 0;
 	overflow: hidden;
+	padding: 0 0 0 5px;
+}
+
+#instant_messenger_content .titulo span
+{
+	float:left;
+	margin-left: 17px;
 }
 
