package modules.chat.blocks.help
{
	import flash.events.*;
	import flash.display.*;
	import flash.text.*;
	import flash.geom.Rectangle;
	import modules.chat.tabs.BxTab;
	import modules.chat.chat.BxChatPane;
	import modules.chat.chat.message.*;
	import utils.*;
	
	/**
	* Pane object for Help.
	*/
	dynamic public class BxHelpPane extends BxChatPane
	{
		private var
			iPadding:Number = 10,
			aContents:BxList,
			mcCurrent:Object;
		/**
		* @private
		*/
		function BxHelpPane(oTab:Object = null)
		{
			bRemovable = false;
			aContents = new BxList();
			aContents.setHolder(this.mcPane, width - 2*this.mcPane.x, height - 2*this.mcPane.y, 0);
			aContents.left = this.mcPane.getScrollBarWidth() + iPadding;
			aContents.padding = iPadding;
			visible = false;
		}

		/**
		* @private
		*/
		public function init(aData:Object):void
		{
			for(var i:Number=0; i<aData.length; i++)
			{
				var mcContent:Object = aContents.add(new BxContent(aData[i]));
				mcContent.addEventListener(Event.OPEN, onContentClick);
			}
			width = parent.width;
			root.mcBlocks.mcHelp.addEventListener(Event.OPEN, onContentClick);
			onContentClick(new BxXmlEvent(Event.OPEN, aContents.elements[0].id));
		}
		
		private function onContentClick(event:Event):void
		{
			var sTopicId:String = event.data;
			if(mcCurrent != null) mcCurrent.maximized = false;
			mcCurrent = aContents.getByKey("id", sTopicId);
			mcCurrent.maximized = true;
			aContents.refresh();
			this.mcPane.scrollTo(mcCurrent.y);
		}
		/**
		* @private
		*/
		override public function set tab(oTab:Object):void
		{
			super.tab = oTab;
			onTabActive(null);
		}
		/**
		* @private
		*/
		override protected function onTabClose(event:Event):void
		{
			super.onTabClose(event);
			this.visible = false;
		}
		/**
		* @private
		*/
		override public function set width(iWidth:Number):void
		{
			var iPaneWidth:Number = iWidth - 2*this.mcPane.x;
			this.mcPane.setSize(iPaneWidth);
			this.mcBack.width = iWidth;
			iPaneWidth -= this.mcPane.getScrollBarWidth() + iPadding;
			for(var i:Number=0; i<aContents.length; i++)
				aContents.elements[i].width = iPaneWidth;
			aContents.refresh();
		}
		/**
		* @private
		*/
		override public function set height(iHeight:Number):void
		{
			var iShiftY:Number = iHeight - this.mcBack.height;
			this.mcPane.setSize(-1, iHeight - 2*this.mcPane.y);
			this.mcBack.height = iHeight;
		}
	}
}