package {
	import com.greensock.TweenLite;
	import com.netgrind.core.Utils;
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.geom.Point;
	
	/**
	 * ...
	 * @author netgrind
	 */
	public class Mirror extends Sprite {
		
		[Embed(source = "../lib/ui_rearmirror.png")]public var uiMirror:Class;
		
		public var charHolder:Sprite;
		public var mirrorMask:Bitmap;
		private var chars:Array = [null,null,null,null,null,null,null,null,null];
		
		public function Mirror() {
			super();
			var mirror:Bitmap = new uiMirror();
			addChild(mirror);
			charHolder = new Sprite();
			addChild(charHolder);
			mirrorMask = new uiMirror();
			addChild(mirrorMask);
			charHolder.mask = mirrorMask;
		}
		
		public function addChar(char:int):void {
			if (chars[char] != null) Utils.removeChild(chars[char], false);
			chars[char] = new FaceSprite(new CharacterManager.sprites[char](), CharacterManager.faceSizes[char]);
			charHolder.addChild(chars[char]);
			reposition();
		}
		
		public function removeChar(char:int):void {
			if (chars[char] != null) {
				Utils.removeChild(chars[char], false);
				chars[char] = null;
				reposition();
			}
		}
		
		public function reposition():void {
			var space:Number = 200 / charHolder.numChildren;
			for (var i:int = 0; i < charHolder.numChildren; i++) {
				charHolder.getChildAt(i).x = space * i+50;
				charHolder.getChildAt(i).y =  charHolder.getChildAt(i).height*.35;
			}
		}
		
	}
	
}