Index: sandbox/jabberit_messenger/trophy/xsl/groups.xsl
===================================================================
--- sandbox/jabberit_messenger/trophy/xsl/groups.xsl	(revision 2339)
+++ sandbox/jabberit_messenger/trophy/xsl/groups.xsl	(revision 2339)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+	<xsl:output method="html" omit-xml-declaration="yes"/>
+	
+	<xsl:param name="nameGroup" />
+	<xsl:param name="id" />
+	
+	<xsl:template match="group">
+
+			<div id="{$id}" style="margin-bottom: 3px;">
+				<span  onclick="loadIM.groupsHidden(this);" style="background: url('images/arrow_down.gif')no-repeat center left;font-weight:bold; padding-left: 16px; cursor: pointer;">
+					<xsl:value-of select="$nameGroup"/>
+				</span>
+			</div>
+			
+	</xsl:template>
+	
+</xsl:stylesheet>
Index: sandbox/jabberit_messenger/trophy/xsl/itensGroup.xsl
===================================================================
--- sandbox/jabberit_messenger/trophy/xsl/itensGroup.xsl	(revision 2339)
+++ sandbox/jabberit_messenger/trophy/xsl/itensGroup.xsl	(revision 2339)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+	<xsl:output method="html" omit-xml-declaration="yes"/>
+	
+	<xsl:param name="nameContact" />
+	<xsl:param name="jid"/>
+	<xsl:param name="id" />
+	<xsl:param name="presence" />
+	
+	<xsl:template match="itens_group">
+
+			<div id="{$id}" onclick="TrophyIM.rosterClick('{$jid}');" style="background: url('images/{$presence}.gif')no-repeat center left; padding-left: 18px; margin:2px 0px 5px 10px; cursor:pointer;">
+				<xsl:value-of select="$nameContact"/>
+			</div>
+			
+	</xsl:template>
+	
+</xsl:stylesheet>
Index: sandbox/jabberit_messenger/trophy/js/loadIM.js
===================================================================
--- sandbox/jabberit_messenger/trophy/js/loadIM.js	(revision 2325)
+++ sandbox/jabberit_messenger/trophy/js/loadIM.js	(revision 2339)
@@ -139,5 +139,5 @@
 		return new ( function( )
 		{
-			this.chatArea		= TrophyIMChatArea;
+			//this.chatArea		= TrophyIMChatArea;
 	
 			this.chatBox		= TrophyIMChatBox;
@@ -158,7 +158,46 @@
 	}
 	
+	
 	function getZindex()
 	{
 		return zIndex++;
+	}
+	
+	function groupsHidden()
+	{
+		if( arguments.length > 0 )
+		{
+			var _element = arguments[0];
+				_element.style.background = "url('images/arrow_right.gif')no-repeat center left";
+				_element.onclick = function(){ groupsVisible(_element);};
+				
+				// Hidden all
+				var _elementNext = _element.nextSibling;
+				
+				while( _elementNext )
+				{	
+					_elementNext.style.display = "none";
+					_elementNext = _elementNext.nextSibling;
+				}
+		}
+	}
+	
+	function groupsVisible()
+	{
+		if( arguments.length > 0 )
+		{
+			var _element = arguments[0];
+				_element.style.background = "url('images/arrow_down.gif')no-repeat center left";
+				_element.onclick = function(){ groupsHidden(_element);};
+
+				// Display all
+				var _elementNext = _element.nextSibling;
+				
+				while( _elementNext )
+				{	
+					_elementNext.style.display = "block";
+					_elementNext = _elementNext.nextSibling;
+				}
+		}
 	}
 	
@@ -262,5 +301,5 @@
 			_xtools = new xtools(path);
 	}
-
+	
 	function loadIM()
 	{
@@ -287,4 +326,6 @@
 	loadIM.prototype.configEvents		= configEvents;
 	loadIM.prototype.getZIndex			= getZindex;
+	loadIM.prototype.groupsHidden		= groupsHidden;
+	loadIM.prototype.groupsVisible		= groupsVisible;
 	loadIM.prototype.parse				= parse;
 	loadIM.prototype.setPresence		= setPresence;
Index: sandbox/jabberit_messenger/trophy/js/trophyim.js
===================================================================
--- sandbox/jabberit_messenger/trophy/js/trophyim.js	(revision 2325)
+++ sandbox/jabberit_messenger/trophy/js/trophyim.js	(revision 2339)
@@ -29,8 +29,15 @@
 make sure onload bootstrapping actually preserves existing onloads
 */
-var TROPHYIM_BOSH_SERVICE = '/proxy/xmpp-httpbind';  //Change to suit
-var TROPHYIM_LOG_LINES = 200;
-var TROPHYIM_LOGLEVEL = 0; //0=debug, 1=info, 2=warn, 3=error, 4=fatal
-var TROPHYIM_VERSION = "0.3";
+
+var TROPHYIM_BOSH_SERVICE	= '/proxy/xmpp-httpbind';  //Change to suit
+var TROPHYIM_LOG_LINES		= 200;
+
+//0=debug, 1=info, 2=warn, 3=error, 4=fatal
+var TROPHYIM_LOGLEVEL		= 0; 
+
+var TROPHYIM_VERSION 		= "0.3";
+
+var TROPHYIM_RESOURCE		= "/JABBERITWEB"; 
+
 //Uncomment to make session reattachment work
 //var TROPHYIM_JSON_STORE = "json_store.php";
@@ -56,5 +63,5 @@
 HTMLSnippets = {
 
-		chatArea	: loadIM.HTMLSnippets.chatArea( ),
+		//chatArea	: loadIM.HTMLSnippets.chatArea( ),
 		
         chatBox		: loadIM.HTMLSnippets.chatBox( ),
@@ -160,8 +167,9 @@
      *    object)
      */
-    getHTML : function(page) {
-    	//alert("Page : \n" + page);
+    getHTML : function(page)
+	{
         return this.xmlParse(HTMLSnippets[page]);
     },
+	
     /** Function: getScript
      *  Returns script object with src to given script
@@ -253,4 +261,5 @@
         return cObj;
     },
+	
     /** Function: load
      *
@@ -258,5 +267,6 @@
      *  into it.
      */
-    load : function()
+
+	load : function()
 	{
 		TrophyIM.cookies	= TrophyIM.getCookies();
@@ -274,33 +284,14 @@
 		setTimeout("TrophyIM.showLogin()", 500);
 
-	    /*TrophyIM.cookies = TrophyIM.getCookies();
-        var client_div = document.getElementById('trophyimclient');
-        if (client_div)
-        {
-            TrophyIM.client_div = client_div;
-
-            //load .css
-            //document.getElementsByTagName('head')[0].appendChild(DOMObjects.getHTML('cssLink'));
-            //DOMObjects.getHTML('cssLink');
-            
-            //Load other .js scripts needed
-            document.getElementsByTagName('head')[0].appendChild(DOMObjects.getScript('strophejs/strophe.js'));
-            document.getElementsByTagName('head')[0].appendChild(DOMObjects.getScript('strophejs/md5.js'));
-            document.getElementsByTagName('head')[0].appendChild(DOMObjects.getScript('strophejs/sha1.js'));
-            document.getElementsByTagName('head')[0].appendChild(DOMObjects.getScript('strophejs/b64.js'));
-            document.getElementsByTagName('head')[0].appendChild(DOMObjects.getScript('js/json2.js')); //Keep this script last
-            
-            //Wait a second to give scripts time to load
-            setTimeout("TrophyIM.showLogin()", 500);
-        } else {
-            alert("Cannot load TrophyIM client.\nClient div not found.");
-        }*/
-    },
+   },
+   
     /** Function: storeData
      *
      *  Store all our data in the JSONStore, if it is active
      */
-    storeData : function() {
-        if (TrophyIM.connection && TrophyIM.connection.connected) {
+   storeData : function()
+   {
+        if (TrophyIM.connection && TrophyIM.connection.connected)
+		{
             TrophyIM.setCookie('trophyim_bosh_xid', TrophyIM.connection.jid + "|" +
             TrophyIM.connection.sid + "|" +  TrophyIM.connection.rid);
@@ -392,5 +383,6 @@
      *
      */
-    login : function() {
+    login : function()
+	{
         if (document.getElementById('trophyimloglevel').checked) {
             TrophyIM.setCookie('trophyimloglevel', 1);
@@ -416,5 +408,5 @@
         Strophe.log = TrophyIM.log;
         var barejid  = document.getElementById('trophyimjid').value
-        var fulljid = barejid + '/TrophyIM';
+        var fulljid = barejid + TROPHYIM_RESOURCE;
         TrophyIM.setCookie('trophyimjid', barejid);
         var password = document.getElementById('trophyimpass').value;
@@ -456,5 +448,6 @@
      *  Callback given to Strophe upon connection to BOSH proxy.
      */
-    onConnect : function(status) {
+    onConnect : function(status)
+	{
         if (status == Strophe.Status.CONNECTING) {
             Strophe.info('Strophe is connecting.');
@@ -486,16 +479,10 @@
         var logging_div = TrophyIM.clearClient();
         
-		loadIM.HTMLSnippets.rosterDiv();
-		loadIM.HTMLSnippets.chatArea();
-		
-		//TrophyIM.client_div.appendChild(DOMObjects.getHTML('rosterDiv'));
-        //TrophyIM.client_div.appendChild(DOMObjects.getHTML('chatArea'));
-        //TrophyIM.client_div.appendChild(DOMObjects.getHTML('statusDiv'));
-		
-        if(logging_div)
+        if( logging_div )
 		{
             TrophyIM.client_div.appendChild(logging_div);
             TrophyIM.logging_div = document.getElementById('trophyimlog');
         }
+		
         TrophyIM.rosterObj = new TrophyIMRoster();
         TrophyIM.connection.addHandler(TrophyIM.onVersion, Strophe.NS.VERSION, 'iq', null, null, null);
@@ -503,9 +490,9 @@
         TrophyIM.connection.addHandler(TrophyIM.onPresence, null, 'presence', null, null, null);
         TrophyIM.connection.addHandler(TrophyIM.onMessage, null, 'message', null, null,  null);
-        //Get roster then announce presence.
+        
+		//Get roster then announce presence.
         TrophyIM.connection.send($iq({type: 'get', xmlns: Strophe.NS.CLIENT}).c('query', {xmlns: Strophe.NS.ROSTER}).tree());
         TrophyIM.connection.send($pres().tree());
-        TrophyIM.renderChats();
-        setTimeout("TrophyIM.renderRoster()", 1000);
+		setTimeout("TrophyIM.renderRoster()", 1000);
     },
 	
@@ -574,6 +561,4 @@
     onPresence : function(msg)
 	{
-		//alert('Function onPresence');
-		
 		Strophe.debug("Presence handler");
         var type = msg.getAttribute('type') ? msg.getAttribute('type') : 'available';
@@ -603,5 +588,5 @@
             var contact	= "";
         	
-            if( TrophyIM.rosterObj.roster[barejid.toLowerCase()] )
+            if( TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name'] )
             {
             	contact = TrophyIM.rosterObj.roster[barejid.toLowerCase()]['contact']['name'];
@@ -621,32 +606,4 @@
             TrophyIM.makeChat(from); //Make sure we have a chat window
             TrophyIM.addMessage(message, jid_lower);
-
-            /*	
-            if ( contact )
-            { 
-
-            	//Do we know you?
-                if ( contact['name'] != null )
-                {
-                    message  = contact['name'] + " (" + barejid + "): ";
-                }
-                else
-                {
-                    message = contact['jid'] + ": ";
-                }
-                
-            	message += Strophe.getText(elems[0]);
-                
-            	TrophyIM.makeChat(from); //Make sure we have a chat window
-                TrophyIM.addMessage(message, jid_lower);
-                
-               
-                //if (TrophyIM.activeChats['current'] != jid_lower) {
-                //    TrophyIM.activeChats['divs'][jid_lower][
-                //    'tab'].className = "trophyimchattab trophyimchattab_a";
-                //    TrophyIM.setTabPresence(from,
-                //    TrophyIM.activeChats['divs'][jid_lower]['tab']);
-                //}
-            }*/
         }
         return true;
@@ -698,96 +655,7 @@
 			}
 		);
-		
-    	/*
-    	 * Codigo Original 
-    	 * 
-    	var barejid = Strophe.getBareJidFromJid(fulljid);
-        if (!TrophyIM.activeChats['divs'][barejid]) {
-            var chat_tabs = document.getElementById('trophyimchattabs');
-            var chat_tab = DOMObjects.getHTML('chatTab');
-            var chat_box = DOMObjects.getHTML('chatBox');
-            var contact = TrophyIM.rosterObj.getContact(barejid);
-            var tab_name = (contact['name'] != null) ? contact['name'] : barejid;
-            chat_tab.className = "trophyimchattab trophyimchattab_a";
-            getElementsByClassName('trophyimchattabjid', 'div', chat_tab)[0].appendChild(document.createTextNode(barejid));
-            getElementsByClassName('trophyimchattabname', 'div', chat_tab)[0].appendChild(document.createTextNode(tab_name));
-            chat_tab = chat_tabs.appendChild(chat_tab);
-            TrophyIM.activeChats['divs'][barejid] = {jid:fulljid, tab:chat_tab, box:chat_box};
-            
-            if (!TrophyIM.activeChats['current']) { //We're the first
-                TrophyIM.activeChats['current'] = barejid;
-                document.getElementById('trophyimchat').appendChild(chat_box);
-                TrophyIM.activeChats['divs'][barejid]['box'] = chat_box;
-                TrophyIM.activeChats['divs'][barejid]['tab'].className =
-                "trophyimchattab trophyimchattab_f";
-            }
-            if (!TrophyIM.chatHistory[barejid.toLowerCase()]) {
-                TrophyIM.chatHistory[barejid.toLowerCase()] = {resource: null,
-                history: new Array()};
-            }
-            TrophyIM.setTabPresence(fulljid, chat_tab);
-        }
-        TrophyIM.activeChats['divs'][barejid.toLowerCase()]['resource'] =
-        Strophe.getResourceFromJid(fulljid);
-        TrophyIM.chatHistory[barejid.toLowerCase()]['resource'] =
-        Strophe.getResourceFromJid(fulljid);*/
-        
-    },
-    /** Function showChat
-     *
-     *  Make chat box to given barejid active
-     */
-    showChat : function(barejid) {
-        if (TrophyIM.activeChats['current'] &&
-        TrophyIM.activeChats['current'] != barejid) {
-            var chat_area = document.getElementById('trophyimchat');
-            var active_divs =
-            TrophyIM.activeChats['divs'][TrophyIM.activeChats['current']];
-            active_divs['box'] =
-            chat_area.removeChild(getElementsByClassName('trophyimchatbox',
-            'div', chat_area)[0].parentNode);
-            active_divs['tab'].className = "trophyimchattab trophyimchattab_b";
-            TrophyIM.setTabPresence(TrophyIM.activeChats['current'],
-            active_divs['tab']);
-            TrophyIM.activeChats['divs'][barejid]['box'] =
-            chat_area.appendChild(TrophyIM.activeChats['divs'][barejid]['box']);
-            TrophyIM.activeChats['current'] = barejid;
-            TrophyIM.activeChats['divs'][barejid]['tab'].className =
-            "trophyimchattab trophyimchattab_f";
-            TrophyIM.setTabPresence(barejid,
-            TrophyIM.activeChats['divs'][barejid]['tab']);
-            getElementsByClassName('trophyimchatinput', null,
-            TrophyIM.activeChats['divs'][barejid]['box'])[0].focus();
-        }
-    },
-    /** Function: setTabPresence
-     *
-     *  Applies appropriate class to tab div based on presence
-     *
-     *  Parameters:
-     *    (String) jid - jid to check presence for
-     *    (String) tab_div - tab div element to alter class on
-     */
-    setTabPresence : function(jid, tab_div)
-	{
-        alert('function setTabPresence');
-		
-		var presence = TrophyIM.rosterObj.getPresence(jid);
-        tab_div.className = tab_div.className.replace(" trophyimchattab_av", "");
-        tab_div.className = tab_div.className.replace(" trophyimchattab_aw", "");
-        tab_div.className = tab_div.className.replace(" trophyimchattab_off", "");
-        if (presence) {
-            if (presence['show'] == "chat" || presence['show'] == "available") {
-                tab_div.className += " trophyimchattab_av";
-            } else {
-                tab_div.className += " trophyimchattab_aw";
-            }
-        } else {
-            tab_div.className += " trophyimchattab_off";
-        }
-    },
+    },
+
     /** Function: addMessage
-     *
-     *  Adds message to chat box, and history
      *
      *  Parameters:
@@ -795,32 +663,17 @@
      *    (string) jid - the jid of chat box to add the message to.
      */
+	
     addMessage : function(msg, jid)
     {
     	var chatBox		= document.getElementById(jid + "__chatBox");
     	var messageDiv	= document.createElement("div");
-    		messageDiv.style.margin = "3px 0px 3px 3px";
-    		messageDiv.innerHTML	= msg.contact + " : " + msg.msg ;
+    	
+		messageDiv.style.margin = "3px 0px 3px 3px";
+    	messageDiv.innerHTML	= msg.contact + " : " + msg.msg ;
     		
     	chatBox.appendChild(messageDiv);
     	chatBox.scrollTop = chatBox.scrollHeight;
-        
-        /*
-         * Codigo Original Comentado 
-         *
-        
-    	var chat_box = getElementsByClassName('trophyimchatbox', 'div',
-        TrophyIM.activeChats['divs'][jid]['box'])[0];
-        var msg_div = document.createElement('div');
-        msg_div.className = 'trophyimchatmessage';
-        msg_div.appendChild(document.createTextNode(msg));
-        chat_box.appendChild(msg_div);
-        chat_box.scrollTop = chat_box.scrollHeight;
-        if (TrophyIM.chatHistory[jid]['history'].length > 10) {
-            TrophyIM.chatHistory[jid]['history'].shift();
-        }
-        TrophyIM.chatHistory[jid]['history'][
-        TrophyIM.chatHistory[jid]['history'].length] = msg;
-        */
-    },
+    },
+	
     /** Function: renderRoster
      *
@@ -828,247 +681,175 @@
      *  changed.
      */
-    renderRoster : function() {
-        if (TrophyIM.rosterObj.changes.length > 0) {
-            var roster_div = document.getElementById('trophyimroster');
-            if(roster_div) {
-                var groups = new Array();
-                for (var group in TrophyIM.rosterObj.groups) {
-                    groups[groups.length] = group;
+    
+	renderRoster : function()
+	{
+		if( TrophyIM.rosterObj.changes.length > 0 )
+		{
+			var roster_div = document.getElementById('trophyimroster');
+			
+			if( roster_div )
+			{
+				var groups = new Array();
+				
+                for (var group in TrophyIM.rosterObj.groups)
+				{
+					groups[groups.length] = ( group ) ? group : "SEM GRUPO";
                 }
-                groups.sort();
-                var group_divs = getElementsByClassName('trophyimrostergroup',
-                null, roster_div);
-                for (var g = 0; g < group_divs.length; g++) {
-                    var group_name = getElementsByClassName('trophyimrosterlabel',
-                    null, group_divs[g])[0].firstChild.nodeValue;
-                    while (group_name > groups[0]) {
-                        var new_group = TrophyIM.renderGroup(groups[0], roster_div);
-                        new_group = roster_div.insertBefore(new_group,
-                        group_divs[g]);
-                        if (TrophyIM.rosterObj.groupHasChanges(groups[0])) {
-                            TrophyIM.renderGroupUsers(new_group, groups[0],
-                            TrophyIM.rosterObj.changes.slice());
-                        }
-                        groups.shift();
-                    }
-                    if (group_name == groups[0]) {
-                        groups.shift();
-                    }
-                    if (TrophyIM.rosterObj.groupHasChanges(group_name)) {
-                        TrophyIM.renderGroupUsers(group_divs[g], group_name,
-                        TrophyIM.rosterObj.changes.slice());
-                    }
-                }
-                while (groups.length) {
-                    var group_name = groups.shift();
-                    var new_group = TrophyIM.renderGroup(group_name,
-                    roster_div);
-                    new_group = roster_div.appendChild(new_group);
-                    if (TrophyIM.rosterObj.groupHasChanges(group_name)) {
-                        TrophyIM.renderGroupUsers(new_group, group_name,
-                        TrophyIM.rosterObj.changes.slice());
-                    }
-                }
-            }
-            TrophyIM.rosterObj.changes = new Array();
-            TrophyIM.constants.stale_roster = false;
-        }
-        setTimeout("TrophyIM.renderRoster()", 1000);
-    },
-    /** Function: renderChats
-    *
-    *  Renders chats found in TrophyIM.chatHistory.  Called upon page reload.
-    *  Waits for stale_roster flag to clear before trying to run, so that the
-    *  roster exists
-    */
-    renderChats : function() {
-        if (TrophyIM.constants.stale_roster == false) {
-            if(TrophyIM.JSONStore.store_working) {
-                var data = TrophyIM.JSONStore.getData(['chat_history',
-                'active_chat']);
-                if (data['active_chat']) {
-                    for (var jid in data['chat_history']) {
-                        fulljid = jid + "/" + data['chat_history'][jid]['resource'];
-                        Strophe.info("Makechat " + fulljid);
-                        TrophyIM.makeChat(fulljid);
-                        for (var h = 0; h <
-                        data['chat_history'][jid]['history'].length; h++) {
-                            TrophyIM.addMessage(data['chat_history'][jid]['history'][h],
-                            jid);
-                        }
-                    }
-                    TrophyIM.chat_history = data['chat_history'];
-                    TrophyIM.showChat(data['active_chat']);
-                }
-            }
-        } else {
-            setTimeout("TrophyIM.renderChats()", 1000);
-        }
-    },
-    /** Function: renderGroup
-     *
-     *  Renders actual group label in roster
-     *
-     *  Parameters: 
-     *    (String) group - name of group to render
-     *    (DOM) roster_div - roster div
-     *
-     *  Returns:
-     *    DOM group div to append into roster
-     */
-    renderGroup : function(group, roster_div) {
-        var new_group = DOMObjects.getHTML('rosterGroup');
-        var label_div = getElementsByClassName( 'trophyimrosterlabel', null,
-        new_group)[0];
-        label_div.appendChild(document.createTextNode(group));
-        new_group.appendChild(label_div);
-        return new_group;
-    },
-    /** Function: renderGroupUsers
-     *
-     *  Re-renders user entries in given group div based on status of roster
-     *
-     *  Parameter: (Array) changes - jids with changes in the roster.  Note:
-     *  renderGroupUsers will clobber this.
-     */
-    renderGroupUsers : function(group_div, group_name, changes) {
-        var group_members = TrophyIM.rosterObj.groups[group_name];
-        var member_divs = getElementsByClassName('trophyimrosteritem', null,
-        group_div);
-        for (var m = 0; m < member_divs.length; m++) {
-            member_jid = getElementsByClassName('trophyimrosterjid', null,
-            member_divs[m])[0].firstChild.nodeValue;
-            if (member_jid > changes[0]) {
-                if (changes[0] in group_members) {
-                    var new_presence = TrophyIM.rosterObj.getPresence(
-                    changes[0]);
-                    if(new_presence) {
-                        var new_member = DOMObjects.getHTML('rosterItem');
-                        var new_contact =
-                        TrophyIM.rosterObj.getContact(changes[0]);
-                        getElementsByClassName('trophyimrosterjid', null,
-                        new_member)[0].appendChild(document.createTextNode(
-                        changes[0]));
-                        var new_name = (new_contact['name'] != null) ?
-                        new_contact['name'] : changes[0];
-                        getElementsByClassName('trophyimrostername', null,
-                        new_member)[0].appendChild(document.createTextNode(
-                        new_name));
-                        group_div.insertBefore(new_member, member_divs[m]);
-                        if (new_presence['show'] == "available" ||
-                        new_presence['show'] == "chat") {
-                            new_member.className =
-                            "trophyimrosteritem trophyimrosteritem_av";
-                        } else {
-                            new_member.className =
-                            "trophyimrosteritem trophyimrosteritem_aw";
-                        }
-                    } else {
-                        //show offline contacts
-                    }
-                }
-                changes.shift();
-            } else if (member_jid == changes[0]) {
-                member_presence = TrophyIM.rosterObj.getPresence(member_jid);
-                if(member_presence) {
-                    if (member_presence['show'] == "available" ||
-                    member_presence['show'] == "chat") {
-                        member_divs[m].className =
-                        "trophyimrosteritem trophyimrosteritem_av";
-                    } else {
-                        member_divs[m].className =
-                        "trophyimrosteritem trophyimrosteritem_aw";
-                    }
-                } else {
-                    //show offline status
-                    group_div.removeChild(member_divs[m]);
-                }
-                changes.shift();
-            }
-        }
-        while (changes.length > 0) {
-            if (changes[0] in group_members) {
-                var new_presence = TrophyIM.rosterObj.getPresence(changes[0]);
-                if(new_presence) {
-                    var new_member = DOMObjects.getHTML('rosterItem');
-                    var new_contact =
-                    TrophyIM.rosterObj.getContact(changes[0]);
-                    getElementsByClassName('trophyimrosterjid', null,
-                    new_member)[0].appendChild(document.createTextNode(
-                    changes[0]));
-                    var new_name = (new_contact['name'] != null) ?
-                    new_contact['name'] : changes[0];
-                    getElementsByClassName('trophyimrostername', null,
-                    new_member)[0].appendChild(document.createTextNode(
-                    new_name));
-                    group_div.appendChild(new_member);
-                    if (new_presence['show'] == "available" ||
-                    new_presence['show'] == "chat") {
-                        new_member.className =
-                        "trophyimrosteritem trophyimrosteritem_av";
-                    } else {
-                        new_member.className =
-                        "trophyimrosteritem trophyimrosteritem_aw";
-                    }
-                } else {
-                    //show offline
-                }
-            }
-            changes.shift();
-        }
-    },
+                
+				groups.sort();
+
+				for ( var i = 0; i < groups.length; i++ )
+				{
+					
+					TrophyIM.renderGroups( groups[i] , roster_div );	
+				}
+				
+				TrophyIM.renderItensGroup( roster_div );
+			}
+		}
+			
+		setTimeout("TrophyIM.renderRoster()", 1000 );		
+	},
+
+    /** Function: renderGroups
+     *
+     *
+     */
+	
+	renderGroups: function( nameGroup, elementParent )
+	{
+		var _addGroup = function()
+		{
+			var paramsGroup = 
+			{
+				'nameGroup' : arguments[0],
+				'id'		: (( arguments[0] == "SEM GRUPO" ) ? "sem_grupo_jabber" : "" )
+			}
+			
+			elementParent.innerHTML += loadIM.parse("group","groups.xsl", paramsGroup);
+		}
+		
+		if( !elementParent.hasChildNodes() )
+		{
+			_addGroup(nameGroup);	
+		}
+		else
+		{
+			var elementChild = elementParent.firstChild;
+			var flag = false;
+			
+			while ( elementChild )
+			{
+				if ( elementChild.childNodes[0].childNodes[0].nodeValue === nameGroup )
+				{
+					flag = true;	
+				}
+				elementChild = elementChild.nextSibling;
+			}
+			
+			if( !flag )
+				_addGroup(nameGroup);
+		}
+			
+	},
+
+    /** Function: renderItensGroup
+     *
+     *
+     */
+
+	renderItensGroup : function( elementParent )
+	{
+		var _addItensGroup = function()
+		{
+			if( arguments.length > 0 )
+			{
+				var objContact	= arguments[0];
+				var element		= arguments[1];
+				var itensGroup	= document.getElementById('itenContact_' + objContact.contact.jid);
+
+				if ( itensGroup == null )
+				{
+					// Name
+					var nameContact = "";					
+					
+					if (objContact.contact.name) 
+						nameContact = objContact.contact.name;
+					else
+					{
+						nameContact = objContact.contact.jid;
+						nameContact = nameContact.substring(0, nameContact.indexOf('@'));
+					}
+					
+					// Presence
+					var presence = 'unavailable';
+					
+					if (objContact.presence)
+					{
+						for (var resource in objContact.presence)
+						{
+							presence = objContact.presence[resource].show;
+						}
+					}
+					
+					var paramsContact =
+					{
+						'nameContact' : nameContact,
+						'jid'		  : objContact.contact.jid,	
+						'id'		  : 'itenContact_' + objContact.contact.jid,
+						'presence'	  : presence 
+					}
+					
+					element.innerHTML += loadIM.parse("itens_group", "itensGroup.xsl", paramsContact);
+				}
+				else
+				{
+					// Presence
+					var presence = 'unavailable';
+					
+					if (objContact.presence)
+					{
+						for (var resource in objContact.presence) 
+							presence = objContact.presence[resource].show;
+					}
+
+					itensGroup.style.background = "url('images/" + presence + ".gif')no-repeat center left"; 
+				}
+			}
+		}
+		
+		for ( var userItem in TrophyIM.rosterObj.roster)
+		{
+			if ( TrophyIM.rosterObj.roster[userItem].contact.groups )
+			{
+				var elementChild = elementParent.firstChild
+				
+				while ( elementChild )
+				{
+					if( elementChild.childNodes[0].childNodes[0].nodeValue == TrophyIM.rosterObj.roster[userItem].contact.groups )
+						_addItensGroup( TrophyIM.rosterObj.roster[userItem], elementChild );
+						
+					elementChild = elementChild.nextSibling;
+				}
+			}
+			else
+			{
+				var elementChild = document.getElementById("sem_grupo_jabber");
+				
+				_addItensGroup( TrophyIM.rosterObj.roster[userItem], elementChild );
+			}
+		}
+	},
+	
     /** Function: rosterClick
      *
      *  Handles actions when a roster item is clicked
      */
-    rosterClick : function(roster_item) {
-        var barejid = getElementsByClassName('trophyimrosterjid', null,
-        roster_item)[0].firstChild.nodeValue;
-        var presence = TrophyIM.rosterObj.getPresence(barejid);
-        if (presence && presence['resource']) {
-            var fulljid = barejid + "/" + presence['resource'];
-        } else {
-            var fulljid = barejid;
-        }
+    
+	rosterClick : function(fulljid)
+	{
         TrophyIM.makeChat(fulljid);
-        TrophyIM.showChat(barejid);
-    },
-    /** Function: tabClick
-     *
-     *  Handles actions when a chat tab is clicked
-     */
-    tabClick : function(tab_item) {
-        var barejid = getElementsByClassName('trophyimchattabjid', null,
-        tab_item)[0].firstChild.nodeValue;
-        if (TrophyIM.activeChats['divs'][barejid]) {
-            TrophyIM.showChat(barejid);
-        }
-    },
-    /** Function: tabClose
-     *
-     *  Closes chat tab
-     */
-    tabClose : function(tab_item) {
-        var barejid = getElementsByClassName('trophyimchattabjid', null,
-        tab_item.parentNode)[0].firstChild.nodeValue;
-        if (TrophyIM.activeChats['current'] == barejid) {
-            if (tab_item.parentNode.nextSibling) {
-                TrophyIM.showChat(getElementsByClassName('trophyimchattabjid',
-                null, tab_item.parentNode.nextSibling)[0].firstChild.nodeValue);
-            } else if (tab_item.parentNode.previousSibling) {
-                TrophyIM.showChat(getElementsByClassName('trophyimchattabjid',
-                null, tab_item.parentNode.previousSibling)[0].firstChild.nodeValue);
-            } else { //no other active chat
-                document.getElementById('trophyimchat').removeChild(
-                getElementsByClassName('trophyimchatbox')[0].parentNode);
-                delete TrophyIM.activeChats['current'];
-            }
-        }
-        delete TrophyIM.activeChats['divs'][barejid];
-        delete TrophyIM.chatHistory[barejid];
-        //delete tab
-        tab_item.parentNode.parentNode.removeChild(tab_item.parentNode);
-    },
-    
+    },
+
 	setPresence : function()
 	{
@@ -1109,30 +890,4 @@
     		}
     	}
-    	
-    	
-    	/*
-    	 * Codigo original comentado 
-    	 *
-    	var message_input = getElementsByClassName('trophyimchatinput', null, chat_box.parentNode)[0];
-        var active_jid = TrophyIM.activeChats['current'];
-        
-        if(TrophyIM.activeChats['current'])
-        {
-            var active_chat =
-            TrophyIM.activeChats['divs'][TrophyIM.activeChats['current']];
-            var to = TrophyIM.activeChats['current'];
-            if (active_chat['resource'])
-            {
-                to += "/" + active_chat['resource'];
-            }
-            TrophyIM.connection.send($msg({to: to, from: TrophyIM.connection.jid, type: 'chat'}).c('body').t(message_input.value).tree());
-            
-            TrophyIM.addMessage("Me:\n" + message_input.value,
-            TrophyIM.activeChats['current']);
-        }
-        
-        message_input.value = '';
-        message_input.focus();
-        */
     }
 };
@@ -1146,5 +901,6 @@
  *  roster[jid_lower]['presence'][resource]
  */
-function TrophyIMRoster() {
+function TrophyIMRoster()
+{
     /** Constants: internal arrays
      *    (Object) roster - the actual roster/presence information
@@ -1152,18 +908,25 @@
      *    (Array) changes - array of jids with presence changes
      */
-    if (TrophyIM.JSONStore.store_working) {
+    if (TrophyIM.JSONStore.store_working)
+	{
         var data = TrophyIM.JSONStore.getData(['roster', 'groups']);
         this.roster = (data['roster'] != null) ? data['roster'] : {};
         this.groups = (data['groups'] != null) ? data['groups'] : {};
-    } else {
+    }
+	else
+	{
         this.roster = {};
         this.groups = {};
     }
     this.changes = new Array();
-    if (TrophyIM.constants.stale_roster) {
-        for (var jid in this.roster) {
-            this.changes[this.changes.length] = jid;
-        }
-    }
+    
+	if (TrophyIM.constants.stale_roster)
+	{
+        for (var jid in this.roster)
+		{
+			this.changes[this.changes.length] = jid;
+        }
+    }
+	
     /** Function: addContact
      *
@@ -1176,5 +939,6 @@
      *    (Array) groups - array of groups contact is member of
      */
-    this.addContact = function(jid, subscription, name, groups) {
+    
+	this.addContact = function(jid, subscription, name, groups) {
         var contact = {jid:jid, subscription:subscription, name:name, groups:groups}
         var jid_lower = jid.toLowerCase();
