package modules.chat.blocks.help
{
	import flash.display.*;
	import flash.events.*;
	import modules.chat.blocks.BxProfileButton;
	import utils.*;
	
	/**
	* Dispatched when the topic is being selected. 
	* The topic ID is passed as <code>data</code> value for event.
	*/
	[Event(name="open", type="utils.BxXmlEvent")]
	
	/**
	* Help topic object
	*/	
	dynamic public class BxTopic extends BxProfileButton
	{
		/**
		* @private
		*/
		protected var
			sId:String = "";
			
		/**
		* @private
		*/
		function BxTopic(aData:Object)
		{
			if(aData.id is String) sId = aData.id;
			sCaption = BxXml.replaceXmlCharacters(BxXml.getChildByProperty(aData, "title")["_value"]);
		}
		/**
		* @private
		*/
		override protected function onAddToStage(event:Event):void
		{
			tfSource = root.mcStyle.HelpTopicHeader;
			caption = sCaption;
		}
		/**
		* Changes topic width
		*/
		override public function set width(iWidth:Number):void
		{
			var iShiftX:Number = iWidth - this.txtCaption.x - this.txtCaption.width;
			this.txtCaption.width += iShiftX;
		}
		/**
		* @private
		*/
		override protected function onClick(event:Event):void
		{
			gotoTopic(sId);
		}
		/**
		* @private
		*/
		protected function gotoTopic(sTopicId:String):void
		{
			dispatchEvent(new BxXmlEvent(Event.OPEN, sTopicId));
		}
	}
}