package net.fdms.Action 
{
	import com.adobe.crypto.WSSEUsernameToken;
	import flash.events.MouseEvent;
	/**
	 * ...
	 * @author ...
	 */
	public class MouseAction 
	{
		protected static var mouseOn:Function;
		protected static var mouseOff:Function;
		private static var btnActionLib:Array = [];
		private static var overActionLib:Array = [];
		private static var outActionLib:Array = [];
		public function MouseAction() 
		{
			/*
			[
				[
					target,
					action = [
						{
							id:String,
							action:Array
						}
					]
				]
			]
			*/
		}
		
		public static function mouseAction(target:String, type:int = 0):void {
			//trace(target);
			var foo:Array = getType(type);
			var target:String = target;
			var tmp:Boolean = false;
			var n:int = foo.length;
			for (var a:int = 0; a < n; a++ ) {
				var bn:int = foo[a][1].length;
				for (var b:int = 0; b < bn; b++ ) {
					if (target == foo[a][1][b].id) {
						//MouseActionOff();
						var cn:int = foo[a][1][b].action.length;
						Action.addAction(foo[a][1][b].action);
						tmp = true;
						Action.start();
					}
					if (tmp) break;
				}
				if (tmp) break;
			}
		}
		
		/**
		 * 点击事件
		 * @param	e
		 */
		public static function BtnAction(e:MouseEvent):void {
			mouseAction(e.target.name);
		}
		
		public static function OverAction(e:MouseEvent):void {
			mouseAction(e.target.name, 1);
		}
		
		public static function OutAction(e:MouseEvent):void {
			mouseAction(e.target.name, 2);
		}
		public static function RegMouseAction(mainFunOn:Function, mainFunOff:Function):void {
			mouseOn = mainFunOn;
			mouseOff = mainFunOff;
		}
		
		public static function MouseActionOn():void {
			mouseOn();
		}
		
		public static function MouseActionOff():void {
			mouseOff();
		}
		
		/**
		 * 添加鼠标监听事件
		 * @param	target
		 * @param	btnAction
		 */
		public static function addBtnAction(target:String, btnAction:Array, type:int = 0):void {
			var foo:Array = getType(type);
			if (!checkExist(target,type)) {
				foo.push([target, btnAction]);
			}
			
		}
		/**
		 * 删除鼠标监听事件
		 * @param	target
		 */
		public static function delMouseAction(target:String, type:int = 0):void {
			var foo:Array = getType(type);
			var n:int = foo.length;
			var tmp:Boolean = false;
			for (var a:int = 0; a < n; a++ ) {
				if (foo[a][0] == target) {
					foo[a] = null;
					foo.splice(a, 1);
					tmp = true;
				}
				if (tmp) break;
			}
		}
		
		/**
		 * 判断对象是否存在
		 * @param	target
		 * @return
		 */
		protected static function checkExist(target:String, type:int = 0):Boolean {
			var foo:Array = getType(type);
			var n:int = foo.length;
			var result:Boolean = false;
			var tmp:Boolean = false;
			for (var a:int = 0; a < n; a++ ) {
				if (foo[a][0] == target) {
					result = true;
					tmp = true;
				}
				if (tmp) break;
			}
			return result;
		}
		
		protected static function getType(type:int):Array {
			var tmp:Array = [];
			switch(type) {
				case 0:
					tmp = btnActionLib;
					break;
				case 1:
					tmp = overActionLib;
					break;
				case 2:
					tmp = outActionLib;
					break;
				default:
					tmp = btnActionLib;
					break;
			}
			return tmp;
		}
		
	}

}