package
{
	import com.greensock.TweenLite;
	import com.greensock.TweenMax;
	import flash.ui.Mouse;
	import org.flixel.FlxG;
	import org.flixel.FlxSprite;
	import org.flixel.FlxState;
	

	public class Intro extends FlxState
	{
		
		[Embed(source = "../assets/title_team.jpg")]
		private var TitleTeam : Class;
		private var title_team : FlxSprite;
		
		[Embed(source = "../assets/title_game.jpg")]
		private var TitleGame : Class;
		private var title_game : FlxSprite;
		
		
		[Embed(source = "../assets/bg.png")]
		private var BG : Class;
		private var bg : FlxSprite;

		[Embed(source = "../assets/play2.png")]
		private var PLAY : Class;
		private var play : FlxSprite;
		
		private var state : int = 0;
		
		public function Intro()
		{ // don't do anything here
		}
		
		
		override public function create() : void
		{
			
			Game.Init();
			
			title_team = new FlxSprite(0, 0, TitleTeam);
			add(title_team);
			
			title_game = new FlxSprite(0, 0, TitleGame);
			add(title_game);
			title_game.alpha = 0.0;
			
			bg = new FlxSprite(0, 0, BG);
			add(bg);
			bg.alpha = 0.0;
			
			play = new FlxSprite(290, 320, PLAY);
			play.scale.make(0.3, 0.3);
			
			
			FlxG.bgColor = 0xFF000000;
			
			FlxG.clear_cameras_to_bg_color = true;
		}
		
		
		override public function update() : void
		{
			
			
			if (play.overlapsPoint( FlxG.mouse.getScreenPosition(), true) )
			{
				Mouse.cursor = "button";
			}
			else
			{
				Mouse.cursor = "arrow";
			}
			
			
			if (FlxG.keys.justReleased("ENTER") || FlxG.keys.justReleased("SPACE") || FlxG.mouse.justReleased() && TweenLite.getTweensOf(title_game).length == 0 )
			{
				state++;
				
				if (state == 1)
				{
					
					TweenLite.to(title_game, 1.5, { alpha: 1, onComplete: function() : void { remove(title_team); }  } );
					
					add(title_game );
					add(play);
					
					play.alpha = 0;
					TweenLite.to(play, 0.4, { alpha: 1 } );
					
					TweenMax.to( play, 0.5, { y: "-=10" , repeat: 	-1, yoyo: true } );
					
					//TweenMax.to( b, 0.7, { x: junction_active.x - b.text_field_width / 2, y: junction_active.y, repeat: 	-1, yoyo: true } );
					
					FlxG.flash( 0xffffffff, 0.15 );
				}
				else
				if (state == 2)
				{
					FlxG.flash( 0xffffffff, 0.15 );
					add(bg);
					
					TweenLite.to(play, 1.7, { alpha: 0 } );
					
					TweenLite.to(title_game, 1.7, { alpha: 0 } );
					
					TweenLite.to(bg, 2.5, { alpha: 1,
						onComplete: function() : void { FlxG.switchState( new PlayState() ) }  }
						);
						
					
				}
				
				
			}
			
			super.update();
			
			
		}
		
		
	}

}