Index: sandbox/jabberit_messenger/trophy_expresso/xsl/contactsList.xsl
===================================================================
--- sandbox/jabberit_messenger/trophy_expresso/xsl/contactsList.xsl	(revision 2437)
+++ sandbox/jabberit_messenger/trophy_expresso/xsl/contactsList.xsl	(revision 2471)
@@ -25,8 +25,5 @@
 		</fieldset>
 				
-		<div id="JabberIMRoster" style="margin-top:3px; overflow-y: auto;">
-			<div id="rosterIM_without_groups" />	
-			<div id="rosterIM_with_groups" />
-		</div>
+		<div id="JabberIMRoster" style="margin-top:3px; overflow-y: auto;"></div>
 		 
 	</xsl:template>
Index: sandbox/jabberit_messenger/trophy_expresso/xsl/groups.xsl
===================================================================
--- sandbox/jabberit_messenger/trophy_expresso/xsl/groups.xsl	(revision 2397)
+++ sandbox/jabberit_messenger/trophy_expresso/xsl/groups.xsl	(revision 2471)
@@ -9,5 +9,5 @@
 
 			<div style="margin-bottom: 3px;">
-				<span  onclick="loadIM.groupsHidden(this);" style="background: url('{$path_jabberit}/templates/default/images/arrow_down.gif')no-repeat center left;font-weight:bold; padding-left: 16px; cursor: pointer;">
+				<span  onclick="loadIM.groupsHidden(this);" style="background: url('{$path_jabberit}/templates/default/images/arrow_down.gif')no-repeat center left; font-weight:bold; padding-left: 16px; cursor: pointer;">
 					<xsl:value-of select="$nameGroup"/>
 				</span>
Index: sandbox/jabberit_messenger/trophy_expresso/xsl/itensGroup.xsl
===================================================================
--- sandbox/jabberit_messenger/trophy_expresso/xsl/itensGroup.xsl	(revision 2397)
+++ sandbox/jabberit_messenger/trophy_expresso/xsl/itensGroup.xsl	(revision 2471)
@@ -6,6 +6,7 @@
 	<xsl:param name="jid"/>
 	<xsl:param name="id" />
+	<xsl:param name="index" />
+	<xsl:param name="path_jabberit" />
 	<xsl:param name="presence" />
-	<xsl:param name="path_jabberit" />
 	<xsl:param name="status"/>
 	<xsl:param name="statusDisplay"/>
@@ -13,9 +14,8 @@
 	<xsl:template match="itens_group">
 
-			<div id="{$id}" onmousedown="loadIM.actionButton(event,'{$jid}');" style="background: url('{$path_jabberit}templates/default/images/{$presence}.gif')no-repeat center left; padding-left: 18px; margin:2px 0px 5px 10px; cursor:pointer;">
-				<xsl:value-of select="$nameContact"/><br/>
-				<span style="font-size: 8pt; font-style:italic; display:{$statusDisplay};"><xsl:value-of select="$status"/></span>
+			<div id="{$id}" onmousedown="loadIM.actionButton(event,'{$jid}','{$index}');" style="background: url('{$path_jabberit}templates/default/images/{$presence}.gif')no-repeat center left; padding-left: 20px; margin:2px 0px 0px 10px; cursor:pointer; font-weight:normal;">
+				<xsl:value-of select="$nameContact"/>
 			</div>
-			
+			<span id="span_show_{$id}" style="margin:2px 0px 0px 10px; font-size: 8pt; font-style:italic; display:{$statusDisplay};"><xsl:value-of select="$status"/></span>
 	</xsl:template>
 	
Index: sandbox/jabberit_messenger/trophy_expresso/inc/WebService.php
===================================================================
--- sandbox/jabberit_messenger/trophy_expresso/inc/WebService.php	(revision 2471)
+++ sandbox/jabberit_messenger/trophy_expresso/inc/WebService.php	(revision 2471)
@@ -0,0 +1,53 @@
+<?php
+  /***************************************************************************\
+  *  Expresso - Expresso Messenger                                            *
+  *  	- Alexandre Correia / Rodrigo Souza							          *
+  * ------------------------------------------------------------------------- *
+  *  This program is free software; you can redistribute it and/or modify it  *
+  *  under the terms of the GNU General Public License as published by the    *
+  *  Free Software Foundation; either version 2 of the License, or (at your   *
+  *  option) any later version.                                               *
+  \***************************************************************************/
+
+class WebService
+{
+	public final function getPhotoSession($pUid, $pOu)
+	{
+		$uid = $pUid;
+		if( strpos($pUid, "@") )
+			$uid = substr($pUid, 0, strpos($pUid, "@"));
+		
+		require_once("../../header.session.inc.php");
+		
+		if( isset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pOu][$uid]) )
+		{
+			$photo = imagecreatefromstring($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pOu][$uid]);
+
+			header("Content-Type: image/jpeg");
+			$width = imagesx($photo);
+			$height = imagesy($photo);
+			$twidth = 60;
+			$theight = 80;
+			$small_photo = imagecreatetruecolor ($twidth, $theight);
+			imagecopyresampled($small_photo, $photo, 0, 0, 0, 0,$twidth, $theight, $width, $height);
+			imagejpeg($small_photo,'',100);
+
+			unset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pOu][$uid]);
+
+			return;	
+		}
+	}
+}
+
+// Php - fotos pelo php;
+if(trim($_REQUEST['phpPhoto']) != "")
+{
+	$obj	= new WebService();
+	$ou		= $_REQUEST['phpOu'];
+	$jid	= $_REQUEST['phpPhoto'];
+	
+	$obj->getPhotoSession($jid, $ou);
+}
+
+
+?>
Index: sandbox/jabberit_messenger/trophy_expresso/inc/webservice.php
===================================================================
--- sandbox/jabberit_messenger/trophy_expresso/inc/webservice.php	(revision 2421)
+++ 	(revision )
@@ -1,52 +1,0 @@
-<?php
-  /***************************************************************************\
-  *  Expresso - Expresso Messenger                                            *
-  *  	- Alexandre Correia / Rodrigo Souza							          *
-  * ------------------------------------------------------------------------- *
-  *  This program is free software; you can redistribute it and/or modify it  *
-  *  under the terms of the GNU General Public License as published by the    *
-  *  Free Software Foundation; either version 2 of the License, or (at your   *
-  *  option) any later version.                                               *
-  \***************************************************************************/
-
-class webService
-{
-	public final function getPhotoSession($pUid, $pOu)
-	{
-		$uid = $pUid;
-		if( strpos($pUid, "@") )
-			$uid = substr($pUid, 0, strpos($pUid, "@"));
-		
-		require_once("../../header.session.inc.php");
-		
-		if( isset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pOu][$uid]) )
-		{
-			$photo = imagecreatefromstring($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pOu][$uid]);
-
-			header("Content-Type: image/jpeg");
-			$width = imagesx($photo);
-			$height = imagesy($photo);
-			$twidth = 60;
-			$theight = 80;
-			$small_photo = imagecreatetruecolor ($twidth, $theight);
-			imagecopyresampled($small_photo, $photo, 0, 0, 0, 0,$twidth, $theight, $width, $height);
-			imagejpeg($small_photo,'',100);
-
-			unset($_SESSION['phpgw_info']['jabberit_messenger']['photo'][$pOu][$uid]);
-
-			return;	
-		}
-	}
-}
-
-// Php - fotos pelo php;
-if(trim($_REQUEST['phpPhoto']) != "")
-{
-	$obj	= new webservice();
-	$ou		= $_REQUEST['phpOu'];
-	$jid	= $_REQUEST['phpPhoto'];
-	
-	$obj->getPhotoSession($jid, $ou);
-}
-
-?>
Index: sandbox/jabberit_messenger/trophy_expresso/js/loadIM.js
===================================================================
--- sandbox/jabberit_messenger/trophy_expresso/js/loadIM.js	(revision 2437)
+++ sandbox/jabberit_messenger/trophy_expresso/js/loadIM.js	(revision 2471)
@@ -25,6 +25,7 @@
 		if( arguments.length > 0 )
 		{
-			var e 	= arguments[0];
-			var jid = arguments[1];
+			var e 		= arguments[0];
+			var jid 	= arguments[1];
+			var index	= arguments[2];
 		
 			if ( !e )
@@ -37,5 +38,5 @@
 	
 			if ( ( e.which && e.which > 1 ) || ( e.button && e.button > 1 ) )
-				optionsItensContact(e, jid);
+				optionsItensContact(jid, index);
 			else
 				TrophyIM.rosterClick(jid);
@@ -236,8 +237,8 @@
 	
 			if ( ev.keyCode == 13 )
-				if( element.value.length >= 4 )
+				if( element.value.length >= 3 )
 					searchUser( element.value );	
 				else
-					alert('Your search argument must be longer than 4 characters.');
+					alert('Your search argument must be longer than 3 characters.');
 		}
 	}
@@ -303,6 +304,7 @@
 		if( arguments.length > 0 )
 		{
-			var element = ( arguments[0].target ) ? arguments[0].target : arguments[0].srcElement;
-			var jid 	= arguments[1];
+			var jid 	= arguments[0];
+			var index	= arguments[1];
+			var element = document.getElementById('itenContact_' + jid + '_' + index );
 			
 			if( showhidden == null )
@@ -321,5 +323,5 @@
 			{
 				_itens += '<img src="'+arrow_right.src+'"/>';
-				_itens += '<span style="cursor:pointer; margin:3px;" onclick='+_options[i][1]+'>';
+				_itens += '<span style="cursor:pointer; margin:3px; font-weight:normal;" onclick='+_options[i][1]+'>';
 				_itens += _options[i][0] + '</span><br/>';
 			}
@@ -330,11 +332,11 @@
 				_optionsItens.style.zIndex	= '99999';
 				_optionsItens.innerHTML		= _itens;  
-										  
+				_optionsItens.onclick		= function(){ showhidden.hiddenObject(false); };					  
+				
 				showhidden.action('onmouseover', 'onmouseout', _optionsItens);
 				
-			element.parentNode.onclick		= function(){ showhidden.hiddenObject(false); };
-			element.parentNode.onmouseout	= function(){ showhidden.hiddenObject(false); };
-			element.parentNode.onmouseover	= function(){ showhidden.hiddenObject(true); };
-			element.parentNode.appendChild( _optionsItens );
+			element.onmouseout	= function(){ showhidden.hiddenObject(false); };
+			element.onmouseover	= function(){ showhidden.hiddenObject(true); };
+			element.appendChild( _optionsItens );
 		}
 		
@@ -352,5 +354,18 @@
 	function removeContact(jid)
 	{
-		TrophyIM.removeContact(jid);
+		setTimeout(function()
+		{
+			TrophyIM.removeContact(jid);
+			
+		}, 500);
+	}
+	
+	function removeGroup()
+	{
+		var _parent = arguments[0];
+		
+		if( _parent.childNodes.length <= 2 )
+			_parent.parentNode.removeChild(_parent);
+		
 	}
 	
@@ -428,4 +443,5 @@
 				_statusItens.style.zIndex	= '99999';
 				_statusItens.innerHTML		= _itens;  
+				_statusItens.onclick 		= function(){ showhidden.hiddenObject(false); };
 										  
 				showhidden.action('onmouseover', 'onmouseout', _statusItens);
@@ -526,4 +542,5 @@
 	loadIM.prototype.setSelectEditable	= setSelectEditable;
 	loadIM.prototype.removeContact		= removeContact;
+	loadIM.prototype.removeGroup		= removeGroup;
 	loadIM.prototype.rosterDiv			= rosterDiv;
 	
Index: sandbox/jabberit_messenger/trophy_expresso/js/AddUser.js
===================================================================
--- sandbox/jabberit_messenger/trophy_expresso/js/AddUser.js	(revision 2437)
+++ sandbox/jabberit_messenger/trophy_expresso/js/AddUser.js	(revision 2471)
@@ -11,7 +11,12 @@
 			var group		= document.getElementById('user_group_jabberIM').value;
 			
-			TrophyIM.addContact( jidFrom, jidTo, name, group );
-			
-			_winBuild('add_user_info','remove');
+			if( jidFrom != jidTo )
+			{
+				TrophyIM.addContact( jidFrom, jidTo, name, group );
+				
+				_winBuild('add_user_info','remove');
+			}
+			else
+				alert("Mesmo Usuário !");
 		}
 		
@@ -50,8 +55,8 @@
 								var jid		= _newUser.getAttribute('jid'); 
 								var ou	 	= _newUser.getAttribute('ou');
-
-								var _img_path  = path_jabberit + 'inc/webservice.php?' + Date.parse( new Date );
+								
+								var _img_path  = path_jabberit + 'inc/WebService.php?' + Date.parse( new Date );
 									_img_path += '&phpPhoto=' + jid + '&phpOu=' + ou;
-
+								
 								_newUser.style.backgroundImage = 'url(' + _img_path + ')';
 							}
Index: sandbox/jabberit_messenger/trophy_expresso/js/trophyim.js
===================================================================
--- sandbox/jabberit_messenger/trophy_expresso/js/trophyim.js	(revision 2437)
+++ sandbox/jabberit_messenger/trophy_expresso/js/trophyim.js	(revision 2471)
@@ -198,9 +198,12 @@
         var cObj = {};
         var cookies = document.cookie.split(';');
-        for (var c in cookies) {
-            while (cookies[c].charAt(0)==' ') { 
+        for (var c in cookies)
+        {
+            while (cookies[c].charAt(0)==' ')
+            { 
                 cookies[c] = cookies[c].substring(1,cookies[c].length);
             }
-            if (cookies[c].substr(0, 8) == "trophyim") {
+            if (cookies[c].substr(0, 8) == "trophyim")
+            {
                 var nvpair = cookies[c].split("=", 2);
                 cObj[nvpair[0]] = nvpair[1];
@@ -208,4 +211,5 @@
             }
         }
+        
         return cObj;
     },
@@ -242,4 +246,5 @@
      *  Store all our data in the JSONStore, if it is active
      */
+     
    storeData : function()
    {
@@ -251,4 +256,5 @@
         }
     },
+    
     /**  Function: showlogin
      *
@@ -257,4 +263,5 @@
      *   exists, or creating a new one of we are re-attaching.
      */
+     
     showLogin : function()
 	{
@@ -483,23 +490,34 @@
      *  one exists
      */
-    clearClient : function() {
-        if(TrophyIM.logging_div) {
-            var logging_div = TrophyIM.client_div.removeChild(
-            document.getElementById('trophyimlog'));
-        } else {
+     
+    clearClient : function()
+    {
+        if(TrophyIM.logging_div)
+        {
+            var logging_div = TrophyIM.client_div.removeChild(document.getElementById('trophyimlog'));
+        }
+        else
+        {
             var logging_div = null;
         }
-        while(TrophyIM.client_div.childNodes.length > 0) {
+        
+        while(TrophyIM.client_div.childNodes.length > 0)
+        {
             TrophyIM.client_div.removeChild(TrophyIM.client_div.firstChild);
         }
+        
         return logging_div;
     },
+    
     /** Function: onVersion
      *
      *  jabber:iq:version query handler
      */
-    onVersion : function(msg) {
+     
+    onVersion : function(msg)
+    {
         Strophe.debug("Version handler");
-        if (msg.getAttribute('type') == 'get') {
+        if (msg.getAttribute('type') == 'get')
+        {
             var from = msg.getAttribute('from');
             var to = msg.getAttribute('to');
@@ -512,33 +530,53 @@
         return true;
     },
+    
     /** Function: onRoster
      *
      *  Roster iq handler
      */
+    
     onRoster : function(msg)
 	{
-		//Strophe.debug("Roster handler");
-		
-        var roster_items = msg.firstChild.getElementsByTagName('item');
+    	var roster_items = msg.firstChild.getElementsByTagName('item');
 		
 		for (var i = 0; i < roster_items.length; i++)
 		{
+			with(roster_items[i])
+			{
+				var groups 		= getElementsByTagName('group');	
+				var group_array	= [];
+				
+				for( var g = 0 ; g < groups.length; g++ )
+				{
+					if( groups[g].hasChildNodes() )
+						group_array[group_array.length] = groups[g].firstChild.nodeValue;
+				}
+
+				TrophyIM.rosterObj.addContact(getAttribute('jid'), getAttribute('subscription'), getAttribute('name'), group_array);
+			}
+			
+			/*
 			var groups = roster_items[i].getElementsByTagName('group');
-            var group_array = new Array();
+            
+			var group_array = new Array();
             
 			for (var g = 0; g < groups.length; g++)
 			{
-				group_array[group_array.length] = groups[g].firstChild.nodeValue;
-            }
+				if( groups[g].firstChild != null )
+					group_array[group_array.length] = groups[g].firstChild.nodeValue;
+            }
+			
 			with ( roster_items[i] )
 			{
+				alert(getAttribute('jid') + "\n" + getAttribute('subscription') + "\n" + getAttribute('name'));
 				TrophyIM.rosterObj.addContact(getAttribute('jid'), getAttribute('subscription'), getAttribute('name'), group_array);
 			}
-        }
-        
+			*/
+        }
+
 		if ( msg.getAttribute('type') == 'set' )
 		{
-			TrophyIM.connection.send($iq({type: 'reply', id:
-            msg.getAttribute('id'), to: msg.getAttribute('from')}).tree());
+			var _iq = $iq({type: 'reply', id: msg.getAttribute('id'), to: msg.getAttribute('from')});
+			TrophyIM.connection.send( _iq.tree());
         }
         
@@ -552,9 +590,10 @@
 	{
 		Strophe.debug("Presence handler");
-        var type = msg.getAttribute('type') ? msg.getAttribute('type') : 'available';
-        var show = msg.getElementsByTagName('show').length ? Strophe.getText(msg.getElementsByTagName('show')[0]) : type;
-        var status = msg.getElementsByTagName('status').length ? Strophe.getText(msg.getElementsByTagName('status')[0]) : '';
-        var priority = msg.getElementsByTagName('priority').length ? parseInt(Strophe.getText(msg.getElementsByTagName('priority')[0])) : 0;
-		TrophyIM.rosterObj.setPresence(msg.getAttribute('from'), priority, show, status);
+        var type		= msg.getAttribute('type') ? msg.getAttribute('type') : 'available';
+        var show 		= msg.getElementsByTagName('show').length ? Strophe.getText(msg.getElementsByTagName('show')[0]) : type;
+        var status 		= msg.getElementsByTagName('status').length ? Strophe.getText(msg.getElementsByTagName('status')[0]) : '';
+        var priority	= msg.getElementsByTagName('priority').length ? parseInt(Strophe.getText(msg.getElementsByTagName('priority')[0])) : 0;
+
+        TrophyIM.rosterObj.setPresence(msg.getAttribute('from'), priority, show, status);
 		
         return true;
@@ -566,5 +605,4 @@
     onMessage : function(msg)
     {
-        Strophe.debug("Message handler");
     
         var from = msg.getAttribute('from');
@@ -576,9 +614,12 @@
             var barejid		= Strophe.getBareJidFromJid(from);
             var jid_lower	= barejid.toLowerCase();
-            var contact	= "";
+            var contact		= "";
         	
-            if( TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name'] )
+            if( TrophyIM.rosterObj.roster[barejid] )
             {
-            	contact = TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name'];
+	            if( TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name'] )
+	            {
+	            	contact = TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name'];
+	            }
             }
             else
@@ -597,6 +638,8 @@
             TrophyIM.addMessage(message, jid_lower);
         }
+        
         return true;
     },
+    
     /** Function: makeChat
      *
@@ -604,19 +647,33 @@
      *  given resource
      */
+     
     makeChat : function(fulljid)
     {
-    	
-    	var barjid = Strophe.getBareJidFromJid(fulljid);
+    	var barejid		= Strophe.getBareJidFromJid(fulljid);
+    	var titleWindow	= "";
     	
     	var paramsChatBox =
     	{
-    			'idChatBox' 	: barjid + "__chatBox",
-    			'jidTo'			: barjid,
+    			'idChatBox' 	: barejid + "__chatBox",
+    			'jidTo'			: barejid,
 				'path_jabberit' : path_jabberit
     	};
     	
+        if( TrophyIM.rosterObj.roster[barejid] )
+        {
+            if( TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name'] )
+            {
+            	titleWindow = TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name'];
+            }
+        }
+        else
+        {
+        	titleWindow = barejid.toLowerCase();
+        	titleWindow = contact.substring(0, contact.indexOf('@'));
+        }	
+
     	var winChatBox = 
     	{
-   			 id_window		: "window_chat_area_" + barjid,
+   			 id_window		: "window_chat_area_" + barejid,
 			 width			: 387,
 			 height			: 365,
@@ -627,19 +684,18 @@
 			 resizable		: true,
 			 zindex			: loadIM.getZIndex(),
-			 title			: barjid.substring(0, barjid.indexOf('@')),
+			 title			: titleWindow,
 			 closeAction	: "hidden",
 			 content		: loadIM.parse("chat_box","chatBox.xsl", paramsChatBox)	
     	}
     	
-    	_winBuild(winChatBox)
+    	_winBuild(winChatBox);
 		
-		loadIM.configEvents(
-			document.getElementById( barjid + '__sendBox'),
+		loadIM.configEvents( document.getElementById( barejid + '__sendBox'),
 			'onkeyup', function(e)
 			{
 				if( e.keyCode == 13 )
 				{
-					TrophyIM.sendMessage( barjid );
-					document.getElementById( barjid + '__sendBox').value = '';
+					TrophyIM.sendMessage( barejid );
+					document.getElementById( barejid + '__sendBox').value = '';
 					return false;
 				}
@@ -665,7 +721,8 @@
     	
     	// Add Contact
-    	var newContact = $iq({type: 'set', id: 'setAddContact'});
+    	var _id = TrophyIM.connection.getUniqueId(); 
+		var newContact = $iq({type: 'set', id: _id });
 			newContact = newContact.c('query').attrs({xmlns : 'jabber:iq:roster'});
-			newContact = newContact.c('item').attrs({jid: jidTo, name:name, ask:'subscribe', subscription:'to'});
+			newContact = newContact.c('item').attrs({jid: jidTo, name:name });
 			newContact = newContact.c('group').t(group).tree();
 
@@ -704,22 +761,13 @@
     	if( ( divItenContact = document.getElementById('itenContact_' + jidTo)))
     	{	
+    		loadIM.removeGroup( divItenContact.parentNode );
+    		
     		divItenContact.parentNode.removeChild(divItenContact);
     		
-    		// Delete Object groups
-			for( var nameGroup in TrophyIM.rosterObj.groups )
-				for(var Jid in TrophyIM.rosterObj.groups[nameGroup])
-					if(TrophyIM.rosterObj.groups[nameGroup][Jid] == jidTo )
-						delete TrophyIM.rosterObj.groups[nameGroup][Jid];
-			
-			// Delete Object roster
-			if( TrophyIM.rosterObj.roster[jidTo] )
-				delete TrophyIM.rosterObj.roster[jidTo];
-	 	
-			TrophyIM.rosterObj.save();
-			
 	    	// Remove Contact
-	    	var delContact	= $iq({type: 'set', id: Date.parse( new Date )})
+			var _id	= TrophyIM.connection.getUniqueId(); 	
+	    	var delContact	= $iq({type: 'set', id: _id})
 	    		delContact	= delContact.c('query').attrs({xmlns : 'jabber:iq:roster'});
-	    		delContact	= delContact.c('item').attrs({jid: jidTo, subscription:'remove'});//.tree();
+	    		delContact	= delContact.c('item').attrs({jid: jidTo, subscription:'remove'}).tree();
 	    	
 	    	TrophyIM.connection.send(delContact);
@@ -735,36 +783,40 @@
 	renderRoster : function()
 	{
-		if( TrophyIM.rosterObj.changes.length > 0 )
-		{
-			var roster_div = document.getElementById('JabberIMRoster');
+		var roster_div = document.getElementById('JabberIMRoster');
+		
+		if( roster_div )
+		{
+			var users = new Array();
 			
-			if( roster_div )
-			{
-				var users = new Array();
+			for( var user in TrophyIM.rosterObj.roster )
+			{
+				users[users.length] = TrophyIM.rosterObj.roster[user].contact.jid;
+			}
+
+			users.sort();
+			
+			var groups 		= new Array();
+			var flagGeral	= false;
+			
+			for (var group in TrophyIM.rosterObj.groups)
+			{
+				if( group )
+					groups[groups.length] = group;
 				
-				for( var user in TrophyIM.rosterObj.roster )
-				{
-					users[users.length] = TrophyIM.rosterObj.roster[user].contact.jid;
-				}
+				if( group == "Geral" )
+					flagGeral = true;
+            }
+            
+			if( !flagGeral )
+				groups[groups.length] = "Geral";
 				
-				users.sort();
-				
-				var groups = new Array();
-				
-				for (var group in TrophyIM.rosterObj.groups)
-				{
-					if( group )
-						groups[groups.length] = group;
-                }
-                
-				groups.sort();
-				
-				for ( var i = 0; i < groups.length; i++ )
-				{
-					TrophyIM.renderGroups( groups[i] , roster_div.lastChild );	
-				}
-				
-				TrophyIM.renderItensGroup(users, roster_div);
+			groups.sort();
+			
+			for ( var i = 0; i < groups.length; i++ )
+			{
+				TrophyIM.renderGroups( groups[i] , roster_div );	
 			}
+			
+			TrophyIM.renderItensGroup( users, roster_div );
 		}
 			
@@ -781,37 +833,43 @@
 		var _addGroup = function()
 		{
+			var _nameGroup	= nameGroup;
+			var _element	= element;
+
 			var paramsGroup = 
 			{
-				'nameGroup' 	: arguments[0],
+				'nameGroup' 	: _nameGroup,
 				'path_jabberit' : path_jabberit
 			}
 			
-			element.innerHTML += loadIM.parse("group","groups.xsl", paramsGroup);
-			
+			_element.innerHTML += loadIM.parse("group","groups.xsl", paramsGroup);
 		}
 
 		if( !element.hasChildNodes() )
 		{
-			_addGroup(nameGroup);	
+			_addGroup();
 		}
 		else
 		{
-			var elementChild = element;
-			var flag = false;
+			var _NodeChild	= element.firstChild;
+			var flagAdd		= false;
 			
-			while ( elementChild )
-			{
-				if ( elementChild.childNodes[0].childNodes[0].firstChild.nodeValue === nameGroup )
+			while( _NodeChild )
+			{
+				if( _NodeChild.childNodes[0].nodeName.toLowerCase() === "span" )
 				{
-					flag = true;
+					if( _NodeChild.childNodes[0].childNodes[0].nodeValue === nameGroup )
+					{
+						flagAdd = true;
+					}
 				}
 				
-				elementChild = elementChild.nextSibling;
+				_NodeChild = _NodeChild.nextSibling;
 			}
-			
-			if( !flag )
-				_addGroup( nameGroup );
+
+			if( !flagAdd )
+			{
+				_addGroup();
+			}
 		}
-		
 	},
 
@@ -823,11 +881,14 @@
 	renderItensGroup : function( users, element )
 	{
-		var addItemGroup = function()
+		var addItem = function()
 		{
 			if( arguments.length > 0 )
 			{
 				var objContact	= arguments[0];
-				var element		= arguments[1];
-				var itensJid	= document.getElementById( 'itenContact_' + objContact.contact.jid );
+				var group		= arguments[1];
+				var element		= arguments[2];
+				var index		= arguments[3];
+				
+				var itensJid	= document.getElementById( 'itenContact_' + objContact.contact.jid + '_' + index );
 				
 				if( itensJid == null )
@@ -853,6 +914,7 @@
 						for (var resource in objContact.presence)
 						{
-							presence = objContact.presence[resource].show;
-							
+							if( objContact.presence[resource].show != 'invisible' )
+								presence = objContact.presence[resource].show;
+
 							if( objContact.presence[resource].status )
 							{
@@ -867,31 +929,32 @@
 						'nameContact' 	: nameContact,
 						'jid'		  	: objContact.contact.jid,	
-						'id'		  	: 'itenContact_' + objContact.contact.jid,
+						'id'		  	: 'itenContact_' + objContact.contact.jid + '_' + index ,
+						'index'			: index,
+						'path_jabberit'	: path_jabberit,
 						'presence'	  	: presence,
-						'path_jabberit'	: path_jabberit,
 						'status'	  	: status,
 						'statusDisplay'	: statusDisplay
 					}
 					
-					if( element.id == "rosterIM_with_groups" )
+					if( group != "")
 					{
-						var elementChild = element;
-				
-						while ( elementChild )
+						var _NodeChild		= element.firstChild;
+						
+						while( _NodeChild )
 						{
-							if( elementChild.childNodes[0].childNodes[0].firstChild.nodeValue == objContact.contact.groups[0] )
-								elementChild.childNodes[0].innerHTML += loadIM.parse("itens_group", "itensGroup.xsl", paramsContact);
-
-							elementChild = elementChild.nextSibling;
+							if( _NodeChild.childNodes[0].nodeName.toLowerCase() === "span" )
+							{
+								if( _NodeChild.childNodes[0].childNodes[0].nodeValue === group )
+								{
+									_NodeChild.innerHTML += loadIM.parse("itens_group", "itensGroup.xsl", paramsContact);
+								}
+							}
+
+							_NodeChild = _NodeChild.nextSibling;
 						}
-					}
-					else
-					{
-						element.innerHTML += loadIM.parse("itens_group", "itensGroup.xsl", paramsContact);							
-					}
+					}	
 				}
 				else
 				{
-					
 					// Presence e Status
 					var presence 		= "unavailable";
@@ -901,5 +964,5 @@
 					if (objContact.presence)
 					{
-						for (var resource in objContact.presence)
+						for ( var resource in objContact.presence )
 						{
 							presence = objContact.presence[resource].show;
@@ -907,14 +970,25 @@
 							if( objContact.presence[resource].status )
 							{
-								status 			= objContact.presence[resource].status;
+								status 			= " ( " + objContact.presence[resource].status + " ) ";
 								statusDisplay	= "block";
 							}
+						}	
+					}
+						
+					var is_open = itensJid.parentNode.childNodes[0].style.backgroundImage;	
+						is_open = is_open.indexOf("arrow_down.gif");
+					
+					with ( document.getElementById('span_show_' + 'itenContact_' + objContact.contact.jid + '_' + index ) )
+					{
+						if( is_open > 0 )
+						{
+							style.display	= statusDisplay;
+							innerHTML		= status;
 						}
 					}
-
-					itensJid.style.background			= "url('"+path_jabberit+"templates/default/images/" + presence + ".gif')no-repeat center left";
-					itensJid.lastChild.style.display 	= statusDisplay;
-					itensJid.lastChild.innerHTML		= " ( " + status + " ) ";
+					
+					itensJid.style.background	= "url('"+path_jabberit+"templates/default/images/" + presence + ".gif')no-repeat center left";
 				}
+				
 			}
 		}
@@ -923,10 +997,21 @@
 		{
 			if( TrophyIM.rosterObj.roster[users[i]].contact.groups )
-				if( TrophyIM.rosterObj.roster[users[i]].contact.groups[0] )
-					addItemGroup(TrophyIM.rosterObj.roster[users[i]], element.lastChild );
+			{
+				var groups = TrophyIM.rosterObj.roster[users[i]].contact.groups;
+				
+				if( groups.length > 0 )
+				{
+					for( var j = 0; j < groups.length; j++ )
+						addItem( TrophyIM.rosterObj.roster[users[i]], groups[j], element, j );
+				}
 				else
-					addItemGroup(TrophyIM.rosterObj.roster[users[i]], element.firstChild );
+				{
+					addItem( TrophyIM.rosterObj.roster[users[i]], "Geral", element, 0 );
+				}
+			}
 			else
-				addItemGroup(TrophyIM.rosterObj.roster[users[i]], element.firstChild );
+			{
+				addItem( TrophyIM.rosterObj.roster[users[i]], "Geral", element, 0 );
+			}
 		}	
 	},
@@ -1029,4 +1114,28 @@
         }
     }
+
+	/** Function: addChange
+	 *
+	 *  Adds given jid to this.changes, keeping this.changes sorted and
+	 *  preventing duplicates.
+	 *
+	 *  Parameters
+	 *    (String) jid : jid to add to this.changes
+	 */
+	 
+	this.addChange = function(jid)
+	{
+		for (var c = 0; c < this.changes.length; c++)
+		{
+			if (this.changes[c] == jid)
+			{
+				return;
+			}
+		}
+		
+		this.changes[this.changes.length] = jid;
+		
+		this.changes.sort();
+	}
 	
     /** Function: addContact
@@ -1038,33 +1147,44 @@
      *    (String) subscription - subscription attribute for contact
      *    (String) name - name attribute for contact
-     *    (Array) groups - array of groups contact is member of
-     */
-    
-	this.addContact = function(jid, subscription, name, groups)
-	{
-        var contact = { jid:jid, subscription:subscription, name:name, groups:groups }
-        var jid_lower = jid.toLowerCase();
-
-		if ( this.roster[jid_lower] )
-		{
-            this.roster[jid_lower]['contact'] = contact;
-        }
-		else
-		{
-            this.roster[jid_lower] = {contact:contact};
-        }
-
-		groups = groups ? groups : [''];
-        
-		for ( var g = 0; g < groups.length; g++ )
-		{
-			if ( !this.groups[groups[g]] )
-			{
-                this.groups[groups[g]] = {};
-            }
-            
-			this.groups[groups[g]][jid_lower] = jid_lower;
-        }
+     *    (Array)  groups - array of groups contact is member of
+     */
+    
+	this.addContact = function(jid, subscription, name, groups )
+	{
+    	if( jid != loadIM.getUserCurrent().jid )
+    	{ 
+    	 	if( subscription !== "remove" )
+	        {
+		    	var contact		= { jid:jid, subscription:subscription, name:name, groups:groups }
+		        var jid_lower	= jid.toLowerCase();
+		
+				if ( this.roster[jid_lower] )
+				{
+		            this.roster[jid_lower]['contact'] = contact;
+		        }
+				else
+				{
+		            this.roster[jid_lower] = {contact:contact};
+		        }
+		
+				groups = groups ? groups : [''];
+		        
+				for ( var g = 0; g < groups.length; g++ )
+				{
+					if ( !this.groups[groups[g]] )
+					{
+		                this.groups[groups[g]] = {};
+		            }
+		            
+					this.groups[groups[g]][jid_lower] = jid_lower;
+		        }
+	        }
+        	else
+        	{
+        		this.removeContact(jid);
+        	}
+    	}
     }
+    
     /** Function: getContact
      *
@@ -1073,4 +1193,5 @@
      *  Parameter: (String) jid - jid to return
      */
+     
     this.getContact = function(jid)
 	{
@@ -1080,4 +1201,91 @@
         }
     }
+
+   /** Function: getPresence
+	*
+	*  Returns best presence for given jid as Array(resource, priority, show,
+	*  status)
+	*
+	*  Parameter: (String) fulljid - jid to return best presence for
+	*/
+	 
+	this.getPresence = function(fulljid)
+	{
+		var jid = Strophe.getBareJidFromJid(fulljid);
+		var current = null;
+		    
+		if (this.roster[jid.toLowerCase()] && this.roster[jid.toLowerCase()]['presence'])
+		{
+			for (var resource in this.roster[jid.toLowerCase()]['presence'])
+			{
+				var presence = this.roster[jid.toLowerCase()]['presence'][resource];
+				if (current == null)
+				{
+					current = presence
+				}
+				else
+				{
+					if(presence['priority'] > current['priority'] && ((presence['show'] == "chat"
+					|| presence['show'] == "available") || (current['show'] != "chat" ||
+					current['show'] != "available")))
+					{
+						current = presence
+					}
+				}
+			}
+		}
+		return current;
+	}
+
+	/** Function: groupHasChanges
+	 *
+	 *  Returns true if current group has members in this.changes
+	 *
+	 *  Parameters:
+	 *    (String) group - name of group to check
+	 */
+	 
+	this.groupHasChanges = function(group)
+	{
+		for (var c = 0; c < this.changes.length; c++)
+		{
+			if (this.groups[group][this.changes[c]])
+			{
+				return true;
+			}
+		}
+		return false;
+	}
+	
+	/** Function removeContact
+	 *
+	 * Parameters
+	 *	 (String) jid		
+	 */
+	 
+	 this.removeContact = function(jid)
+	 {
+		var groups = this.roster[ jid ].contact.groups;
+		
+		for ( var i = 0; i < groups.length; i++ )
+		{
+			delete this.groups[ groups[ i ] ][ jid ];
+		}
+
+		for ( var i = 0; i < groups.length; i++ )
+		{
+			var contacts = 0;
+			for ( var contact in this.groups[ groups[ i ] ] )
+				contacts++;
+
+			if ( ! contacts )
+				delete this.groups[ groups[ i ] ];
+		}
+
+		// Delete Object roster
+		if( this.roster[jid] )
+			delete this.roster[jid];		
+	 }
+	 
     /** Function: setPresence
      *
@@ -1097,103 +1305,52 @@
         var jid_lower = barejid.toLowerCase();
         
-		if( show != 'unavailable')
-		{
-            if (!this.roster[jid_lower])
-			{
-                this.addContact(barejid, 'not-in-roster');
-            }
-            var presence =
-			{
-                resource:resource, priority:priority, show:show, status:status
-            }
-            
-			if (!this.roster[jid_lower]['presence'])
-			{
-                this.roster[jid_lower]['presence'] = {}
-            }
-            this.roster[jid_lower]['presence'][resource] = presence
-        }
-		else if (this.roster[jid_lower] && this.roster[jid_lower]['presence'] && this.roster[jid_lower]['presence'][resource])
-		{
-            delete this.roster[jid_lower]['presence'][resource];
-        }
-        
-		this.addChange(jid_lower);
-        
-		if (TrophyIM.activeChats['divs'][jid_lower])
-		{
-            TrophyIM.setTabPresence(jid_lower, TrophyIM.activeChats['divs'][jid_lower]['tab']);
+        if( barejid != loadIM.getUserCurrent().jid )
+        {
+			if( show != 'unavailable')
+			{
+	            if (!this.roster[jid_lower])
+				{
+	                this.addContact(barejid, 'not-in-roster');
+	            }
+	            var presence =
+				{
+	                resource:resource, priority:priority, show:show, status:status
+	            }
+	            
+				if (!this.roster[jid_lower]['presence'])
+				{
+	                this.roster[jid_lower]['presence'] = {}
+	            }
+	            this.roster[jid_lower]['presence'][resource] = presence
+	        }
+			else if (this.roster[jid_lower] && this.roster[jid_lower]['presence'] && this.roster[jid_lower]['presence'][resource])
+			{
+	            delete this.roster[jid_lower]['presence'][resource];
+	        }
+	        
+			this.addChange(jid_lower);
+	        
+			if (TrophyIM.activeChats['divs'][jid_lower])
+			{
+	            TrophyIM.setTabPresence(jid_lower, TrophyIM.activeChats['divs'][jid_lower]['tab']);
+	        }
         }
     }
-    /** Function: addChange
-     *
-     *  Adds given jid to this.changes, keeping this.changes sorted and
-     *  preventing duplicates.
-     *
-     *  Parameters
-     *    (String) jid : jid to add to this.changes
-     */
-    this.addChange = function(jid) {
-        for (var c = 0; c < this.changes.length; c++) {
-            if (this.changes[c] == jid) {
-                return;
-            }
-        }
-        this.changes[this.changes.length] = jid;
-        this.changes.sort();
-    }
-    /** Function: getPresence
-     *
-     *  Returns best presence for given jid as Array(resource, priority, show,
-     *  status)
-     *
-     *  Parameter: (String) fulljid - jid to return best presence for
-     */
-    this.getPresence = function(fulljid) {
-        var jid = Strophe.getBareJidFromJid(fulljid);
-        var current = null;
-        if (this.roster[jid.toLowerCase()] &&
-        this.roster[jid.toLowerCase()]['presence']) {
-            for (var resource in this.roster[jid.toLowerCase()]['presence']) {
-                var presence = this.roster[jid.toLowerCase()]['presence'][resource];
-                if (current == null) {
-                    current = presence
-                } else {
-                    if(presence['priority'] > current['priority'] && ((presence['show'] == "chat"
-                    || presence['show'] == "available") || (current['show'] != "chat" ||
-                    current['show'] != "available"))) {
-                        current = presence
-                    }
-                }
-            }
-        }
-        return current;
-    }
-    /** Function: groupHasChanges
-     *
-     *  Returns true if current group has members in this.changes
-     *
-     *  Parameters:
-     *    (String) group - name of group to check
-     */
-    this.groupHasChanges = function(group) {
-        for (var c = 0; c < this.changes.length; c++) {
-            if (this.groups[group][this.changes[c]]) {
-                return true;
-            }
-        }
-        return false;
-    }
-    /** Fuction: save
-     *
-     *  Saves roster data to JSON store
-     */
-    this.save = function() {
-        if (TrophyIM.JSONStore.store_working) {
-            TrophyIM.JSONStore.setData({roster:this.roster,
-            groups:this.groups, active_chat:TrophyIM.activeChats['current'],
-            chat_history:TrophyIM.chatHistory});
-        }
-    }
+
+	/** Fuction: save
+	 *
+	 *  Saves roster data to JSON store
+	 */
+	
+	this.save = function()
+	{
+		if (TrophyIM.JSONStore.store_working)
+		{
+			TrophyIM.JSONStore.setData({roster:this.roster,
+			groups:this.groups, active_chat:TrophyIM.activeChats['current'],
+			chat_history:TrophyIM.chatHistory});
+		}
+	}
+
 }
 /** Class: TrophyIMJSONStore
Index: sandbox/jabberit_messenger/trophy_expresso/teste.php
===================================================================
--- sandbox/jabberit_messenger/trophy_expresso/teste.php	(revision 2411)
+++ 	(revision )
@@ -1,39 +1,0 @@
-<?php
-
-//COM PARAMETRO
-// act=$this.contacts_im.list_contacts&name=alexandre
-
-//SEM PARAMETRO
-//act=$this.preferences.getPreferences
-//act=$this.teste.aqui_dentro
-
-$request_method = '_' . $_SERVER['REQUEST_METHOD'];
-
-switch ( $request_method )
-{
-	case '_GET' :
-		$params = $_GET;
-	break;
-	case '_POST' :
-		$params = $_POST;
-	break;
-	case '_HEAD' :
-	case '_PUT' :
-	default :
-		echo "controller - request method not avaible";
-		return false;
-}
-
-if( file_exists(dirname(__FILE__) . "/inc/Controller.class.php") )
-{
-	require_once dirname(__FILE__) . '/inc/Controller.class.php';
-	
-	$controller = new Controller();
-	
-	printf("%s", $controller->exec($$request_method, dirname(__FILE__)));
-	
-	exit(0);
-
-}
-
-?>
