package net.fdms.Function.Align 
{
	import flash.display.DisplayObject;
	import net.fdms.Frame.StageSets;
	import net.fdms.Resource.Resource;
	/**
	 * ...
	 * @author Dawnboy
	 */
	public class AlignSets 
	{
		
		private static var normalAlignQueue:Array = [];
		private static var positionAlignQueue:Array = [];
		public function AlignSets() 
		{
			/**
			 * [target:dsp,alignSets:ob,reset:]
			 */
			
		}
		
		public static function align():void {
			var n:int = normalAlignQueue.length;
			for (var a:int = 0; a < n; a++) {
				AlignLib.normalAlign(normalAlignQueue[a][0], normalAlignQueue[a][1]);
			}
			n = positionAlignQueue.length;
			for (var b:int = 0; b < n; b++) {
				
				AlignLib.positionAlign(positionAlignQueue[b][0], positionAlignQueue[b][1]);
			}
		}
		
		/**
		 * 添加对齐对象
		 * @param	target
		 * @param	alignSets
		 * @param	reset
		 */
		public static function addAlignRes(target:DisplayObject, config:Object):void {
			if (checkAlignType(config.alignSets)) {
				positionAlignQueue.push([target,config]);
			}else {
				normalAlignQueue.push([target,config]);
			}
			align();
		}
		
		public static function delAlign(target:DisplayObject):void {
			var config:Object = Resource.getConfig(target);
			var n:int = normalAlignQueue.length;
			for (var a:int = 0; a < n; a++) {
				if (target == normalAlignQueue[a][0]) {
					normalAlignQueue.splice(a, 1);
					if(config) config.alignSets = undefined;
					break;
				}
			}
			n = positionAlignQueue.length;
			for (var b:int = 0; b < n; b++) {
				if (target == positionAlignQueue[b][0]) {
					positionAlignQueue.splice(b, 1);
					if(config) config.alignSets = undefined;
				}
			}
			align();
		}
		
		/**
		 * 判断对齐对对象是否存在
		 * @param	target
		 * @return
		 */
		/*public static function checkExits(target:DisplayObject ):Boolean {
			var n:int = _alignQueue.length;
			var foo:Boolean = false;
			for (var a:int = 0; a < n; a ++ ) {
				if (_alignQueue[a][0] == target) {
					foo = true;
					break;
				}
			}
			return foo;
		}*/
		
		/**
		 * 获取对齐方式类型
		 * @param	alignSets
		 * @return
		 */
		private static function checkAlignType(alignSets:Array):Boolean {
			
			var n:int = alignSets.length;
			var result:Boolean = false;
			for (var x:int = 0; x < n; x++) {
				var m:int = alignSets[x].toString().length;
				for (var h:int = 0; h < m; h++) {
					//if ("@" == alignSets[x].charAt(h) || "%" == alignSets[x].charAt(h)) {
					//	result = true;
					//	break;
					//}
					
				}
				if (result) break;
			}
			return result;
			
		}
		
	}

}