Index: sandbox/jabberit_messenger/trophy_expresso/js/trophyim.js
===================================================================
--- sandbox/jabberit_messenger/trophy_expresso/js/trophyim.js	(revision 2641)
+++ sandbox/jabberit_messenger/trophy_expresso/js/trophyim.js	(revision 2647)
@@ -137,5 +137,20 @@
 		
 	autoConnection : { connect : true },
-		
+
+	/** Object: chatHistory
+    *
+    *  Stores chat history (last 10 message) and current presence of active
+    *  chat tabs.  Indexed by jid.
+    */
+	
+	chatHistory : {},
+	
+	/** Constants:
+    *
+    *    (Boolean) stale_roster - roster is stale and needs to be rewritten.
+    */
+	
+	constants : {stale_roster: false},
+	
 	/** PosWindow
 	 * 
@@ -149,17 +164,11 @@
 	statusConn : { connected : false },
 	
-	/** Constants:
-     *
-     *    (Boolean) stale_roster - roster is stale and needs to be rewritten.
-     */
-    constants : {stale_roster: false},
-    
-	/** Object: chatHistory
-     *
-     *  Stores chat history (last 10 message) and current presence of active
-     *  chat tabs.  Indexed by jid.
-     */
-    chatHistory : {},
-    
+	/** TimeOut Render Roster
+	 * 
+	 * 
+	 */
+	
+	_timeOut : { renderRoster : null },
+	
      /** Function: setCookie
      *
@@ -207,13 +216,15 @@
         var cObj = {};
         var cookies = document.cookie.split(';');
-        for (var c in cookies)
+        
+        for(var i = 0 ; i < cookies.length; i++ )
         {
-        	while ( cookies[c].charAt(0) == ' ')
+        	while ( cookies[i].charAt(0) == ' ')
             { 
-                cookies[c] = cookies[c].substring(1,cookies[c].length);
-            }
-            if (cookies[c].substr(0, 8) == "trophyim")
+                cookies[i] = cookies[i].substring(1,cookies[i].length);
+            }
+        	
+            if (cookies[i].substr(0, 8) == "trophyim")
             {
-                var nvpair = cookies[c].split("=", 2);
+                var nvpair = cookies[i].split("=", 2);
                 cObj[nvpair[0]] = nvpair[1];
                 TrophyIM.setCookie(nvpair[0], nvpair[1]);
@@ -239,5 +250,6 @@
 			
 			//Load other .js scripts needed
-			document.getElementsByTagName('head')[0].appendChild(DOMObjects.getScript(path_jabberit + 'js/strophe.min.js'));
+			//document.getElementsByTagName('head')[0].appendChild(DOMObjects.getScript(path_jabberit + 'js/strophe.min.js'));
+			document.getElementsByTagName('head')[0].appendChild(DOMObjects.getScript(path_jabberit + 'js/strophe.js'));
 			document.getElementsByTagName('head')[0].appendChild(DOMObjects.getScript(path_jabberit + 'js/json2.js')); //Keep this script last
 			//Wait a second to give scripts time to load
@@ -427,11 +439,10 @@
     onConnect : function(status)
 	{
-		var loading_gif = document.getElementById("JabberIMRosterLoadingGif");
-		
-		loading_gif.style.display = "block";
+    	var loading_gif = document.getElementById("JabberIMRosterLoadingGif");
 		
     	if( status == Strophe.Status.CONNECTING )
 		{
-			Strophe.info('Strophe is connecting.');
+    		loading_gif.style.display = "block";
+    		Strophe.info('Strophe is connecting.');
         }
 		
@@ -440,4 +451,5 @@
 			TrophyIM.delCookie('trophyim_bosh_xid');
             TrophyIM.statusConn.connected = false;
+            loading_gif.style.display = "block";
         }
 		
@@ -451,4 +463,6 @@
 			if( TrophyIM.autoConnection.connect )
 			{
+				loading_gif.style.display = "block";
+				
 				TrophyIM.delCookie('trophyim_bosh_xid');
 	            
@@ -876,6 +890,4 @@
 				loading_gif.style.display = "none";
 				
-			//	loading_gif.parentNode.removeChild(loading_gif);
-			
 			for( var user in TrophyIM.rosterObj.roster )
 			{
@@ -910,5 +922,5 @@
 		}
 			
-		setTimeout("TrophyIM.renderRoster()", 1000 );		
+		TrophyIM._timeOut.renderRoster = setTimeout("TrophyIM.renderRoster()", 1000 );		
 	},
 	
@@ -1231,11 +1243,35 @@
      */
 
-	setPresence : function( type )
-	{
-		if( type != 'status')
-		{
-			if(type == "unavailable")
-			{
-		    	TrophyIM.autoConnection.connect = false;
+	setPresence : function( _type )
+	{
+		if( _type != 'status')
+		{
+			if( _type == "unavailable")
+			{
+				var loading_gif = document.getElementById("JabberIMRosterLoadingGif");
+				
+				if( TrophyIM._timeOut.renderRoster != null )
+					clearTimeout(TrophyIM._timeOut.renderRoster);
+				
+				TrophyIM.connection.send($pres({type : _type}).tree());
+				
+				for( var i = 0; i < TrophyIM.connection._requests.length; i++ )
+		    	{
+		    		if( TrophyIM.connection._requests[i] )
+		    			TrophyIM.connection._removeRequest(TrophyIM.connection._requests[i]);
+		    	}
+				
+				TrophyIM.logout();
+				
+		    	loadIM.clrAllContacts();
+		    	
+		    	delete TrophyIM.rosterObj.roster;
+		    	delete TrophyIM.rosterObj.groups;
+		    	
+		    	setTimeout(function()
+		    	{
+					if( loading_gif.style.display == "block" )
+						loading_gif.style.display = "none";
+		    	}, 1000);
 			}
 			else
@@ -1247,5 +1283,5 @@
 				}
 				else
-					TrophyIM.connection.send($pres( ).c('show').t(type).tree());
+					TrophyIM.connection.send($pres( ).c('show').t(_type).tree());
 			}
 		}
