  */
 package org.igniterealtime.xiff.im
 {
+	import flash.events.EventDispatcher;
+
 	import mx.collections.ArrayCollection;
-	
-	import flash.events.EventDispatcher;
-	import flash.utils.Dictionary;
-	
+
 	import org.igniterealtime.xiff.core.*;
 	import org.igniterealtime.xiff.data.*;
 	import org.igniterealtime.xiff.data.im.*;
 	import org.igniterealtime.xiff.events.*;
-	
+
 	/**
 	 * Broadcast whenever someone revokes your presence subscription. This is not
 	 * an event that is fired when you revoke a subscription, but rather when one of your

				item.status = presence.status;
				item.show = presence.show;
				item.priority = presence.priority;
				if (!presence.type)
				{
					item.online = true;
				}
				else if (presence.type == Presence.UNAVAILABLE_TYPE)
				{
					item.online = false;
				}
				
				var event:RosterEvent = new RosterEvent(RosterEvent.USER_PRESENCE_UPDATED);
				event.jid = item.jid;
				event.data = item;
				dispatchEvent(event);
				
				_presenceMap[item.jid.toString()] = presence;
			}
			catch (e:Error)
			{
				trace(e.getStackTrace());
			}
		}
		
		/**
		 * Get the Presence of the given user if any.
		 * @param	jid
		 * @return
		 */
		public function getPresence(jid:UnescapedJID):Presence
		{
			return _presenceMap[jid.toString()] as Presence;
		}
		
		/**
		 * Get a group by given name
		 * @param	name
		 * @return
		 */
		public function getGroup(name:String):RosterGroup
		{
			return _groups[name] as RosterGroup;
		}
		
		/**
		 * The instance of the XMPPConnection class to use for the roster to use for
		 * sending and receiving data.

		 */
		public function fetchRoster():void
		{
			var tempIQ:IQ = new IQ( null, IQ.GET_TYPE, XMPPStanza.generateID( "roster_" ),
									"fetchRoster_result", this );
			tempIQ.addExtension( new RosterExtension( tempIQ.getNode() ) );
			_connection.send( tempIQ );
		}

		/**
		 *
		 * @param	resultIQ
		 */
		public function fetchRoster_result( resultIQ:IQ ):void
		{
			// Clear out the old roster
			removeAll();
			try
			{
				disableAutoUpdate();
				for each ( var ext:RosterExtension in resultIQ.getAllExtensionsByNS( RosterExtension.NS ) )
				{
					for each ( var item:*in ext.getAllItems() )
					{
						//var classInfo:XML = flash.utils.describeType(item);
						if ( !item is XMLStanza )
						{
							continue;
						}

						var askType:String = item.askType != null ? item.askType.toLowerCase() :
							RosterExtension.ASK_TYPE_NONE;
						addRosterItem( new UnescapedJID( item.jid ), item.name, RosterExtension.SHOW_UNAVAILABLE,
									   "Offline", item.groupNames, item.subscription.toLowerCase(),
									   askType );
					}
				}
				enableAutoUpdate();

				// Fire Roster Loaded Event
				var rosterEvent:RosterEvent = new RosterEvent( RosterEvent.ROSTER_LOADED,
															   false, false );
				dispatchEvent( rosterEvent );
			}
			catch ( e:Error )
			{
				trace( e.getStackTrace() );
			}
		}

		/**
		 *
		 * @param	item
		 * @return
		 */
		public function getContainingGroups( item:RosterItemVO ):Array
		{
			var result:Array = [];
			for ( var key:String in _groups )
			{
				var group:RosterGroup = _groups[ key ] as RosterGroup;
				if ( group.contains( item ) )
				{
					result.push( group );
				}
			}
			return result;
		}

		/**
		 * Get a group by given name
		 * @param	name
		 * @return
		 */
		public function getGroup( name:String ):RosterGroup
		{
			return _groups[ name ] as RosterGroup;
		}

		/**
		 * Get the Presence of the given user if any.
		 * @param	jid
		 * @return
		 */
		public function getPresence( jid:UnescapedJID ):Presence
		{
			return _presenceMap[ jid.toString() ] as Presence;
		}

		/**
		 * Grants a user or service authorization for subscribing to your presence. Once authorization
		 * is granted, the user can see whether you are offline, online, away, etc. Subscriptions can
