package
{
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import flash.net.navigateToURL;
	import flash.net.URLRequest;
	import flash.ui.Keyboard;
	import flinjin.Flinjin;
	import flinjin.graphics.Layer;
	import flinjin.graphics.Sprite;
	import Game.GameMain;
	
	/**
	 * ...
	 * @author Michael Miriti
	 */
	public class Intro extends Layer
	{
		[Embed(source="bmp/intro/igdc-logo.png")]
		private static var _igdclogoBitmap:Class;
		private static var _igdclogoSprite:Sprite = new Sprite(new _igdclogoBitmap());
		
		[Embed(source="bmp/intro/flinjin-logo.png")]
		private static var _flinjinlogoBitmap:Class;
		private static var _flinjinlogoSprite:Sprite = new Sprite(new _flinjinlogoBitmap());
		
		private var _counter:int = 0;
		
		public function Intro()
		{
			FillColor = 0xff000000;
			super(Flinjin.sceneWidth, Flinjin.sceneHeight);
			
			_igdclogoSprite.setCenterInBitmapCenter();
			_igdclogoSprite.alpha = 0;
			
			_flinjinlogoSprite.setCenterInBitmapCenter();
			_flinjinlogoSprite.alpha = 0;
			
			addSprite(_igdclogoSprite, width / 2, height / 2);
			addSprite(_flinjinlogoSprite, width / 2, height / 2);
			
			addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
			addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
		}
		
		override public function Move():void
		{
			if (_counter >= 300)
			{
				startMenu();
				return;
			}
			
			if (_counter < 60)
			{
				_igdclogoSprite.alpha = _counter / 60;
			}
			
			if ((_counter > 120) && (_counter < 180))
			{
				_igdclogoSprite.alpha = 1 - ((_counter - 120) / 60);
				_flinjinlogoSprite.alpha = ((_counter - 120) / 60);
			}
			
			if (_counter > 240)
			{
				_flinjinlogoSprite.alpha = 1 - ((_counter - 240) / 60);
			}
			
			_counter++;
			super.Move();
		}
		
		private function startMenu():void
		{
			Flinjin.Instance.Camera.LookAt(new Menu());
		}
		
		private function onKeyDown(e:KeyboardEvent):void
		{
			if ((e.keyCode = Keyboard.ENTER) || (e.keyCode = Keyboard.SPACE))
			{
				startMenu();
			}
		}
		
		private function onMouseDown(e:MouseEvent):void
		{
			var igdcUrl:URLRequest = new URLRequest("http://igdc.ru");
			var flinjinUrl:URLRequest = new URLRequest("http://www.flinjin.com/");
			if (_counter < 120)
			{
				navigateToURL(igdcUrl);
			}
			else
			{
				navigateToURL(flinjinUrl);
			}
		}
	
	}

}