package {
	import com.netgrind.core.Scheduler;
	import flash.display.Sprite;
	
	/**
	 * ...
	 * @author netgrind
	 */
	public class Countdown extends Sprite {
		
		public function Countdown() {
			super();
		}
		public var callback:Function;
		
		public function start(callback:Function):void  {
			this.callback = callback;
			graphics.clear();
			graphics.beginFill(0xff0000, .5);
			graphics.drawCircle(0, 0, 100);
			Scheduler.invokeInMS(ready);
		}
		
		public function ready():void  {
			graphics.clear();
			graphics.beginFill(0xff9900, .5);
			graphics.drawCircle(0, 0, 100);
			Scheduler.invokeInMS(getset);
		}
		
		public function getset():void {
			graphics.clear();
			graphics.beginFill(0xffff00, .5);
			graphics.drawCircle(0, 0, 100);
			Scheduler.invokeInMS(go);
		}
		
		public function go():void  {
			graphics.clear();
			graphics.beginFill(0x00ff00, .5);
			graphics.drawCircle(0, 0, 100);
			a = 0.5;
			Scheduler.invokeEvery(fade);
			if (callback != null) callback();
		}
		public var a:Number = .5;
		private function fade():void {
			a -= .05;
			graphics.clear();
			graphics.beginFill(0x00ff00, a);
			graphics.drawCircle(0, 0, 100);
		}
		
	}
	
}