package  
{
	import net.flashpunk.Entity;
	import net.flashpunk.FP;
	import net.flashpunk.graphics.Spritemap;
	import net.flashpunk.World
	import net.flashpunk.graphics.Image;
	import net.flashpunk.utils.Draw;
	import net.flashpunk.utils.Input;
	/**
	 * ...
	 * @author AntoineGuerchais
	 */
	public class MainMenu extends World
	{
		
		[Embed(source = '../assets/graphics/menubg.jpg')]
		private const Background:Class;
		[Embed(source = '../assets/graphics/menu_multiply.jpg')]
		private const Foreground:Class;
		[Embed(source = '../assets/graphics/menubg_tuto.png')]
		private const Tuto:Class;
		[Embed(source = '../assets/graphics/menubg_btn.png')]
		private const BGButton:Class;
		[Embed(source = '../assets/graphics/menu_title.png')]
		private const Title:Class;
		[Embed(source = '../assets/graphics/btn_play.png')]
		private const BTNPlay:Class;
		[Embed(source = '../assets/graphics/btn_credits.png')]
		private const BTNCredits:Class;
		[Embed(source = '../assets/graphics/credits.png')]
		private const BGCredits:Class;
		
		private var button:Button;
		
		private var bg:Image;
		private var fg:Image;
		private var tuto:Image;
		private var bgButton:Image;
		private var bgCredits:Image;
		private var title:Image;
		private var play:Spritemap;
		private var credits:Spritemap;
		
		private var init:Boolean = false;
		private var began:Boolean = false;
		private var cre:Boolean = false;
		private var timer:Number = 0.0;
		
		public function MainMenu() 
		{
			//button = new Button();
			//FP.world.add(button);
			//visible = false;
			
			bg = new Image(Background);
			fg = new Image(Foreground);
			tuto = new Image(Tuto);
			tuto.y = FP.screen.height - tuto.height;
			bgButton = new Image(BGButton);
			bgCredits = new Image(BGCredits);
			bgCredits.x = FP.screen.width - bgCredits.width;
			title = new Image(Title);
			play = new Spritemap(BTNPlay, 200, 90);
			play.x = 15;
			play.y = 200;
			credits = new Spritemap(BTNCredits, 200, 90);
			credits.x = 15;
			credits.y = 300;
			fg.blend = "multiply";
			
		}
		
		override public function update():void
		{
			if (!init)
			{
				FP.world.add(new Clipper());
				init = true;
			}
			timer -= FP.elapsed;
			timer = Math.max(timer, 0);
			if (began && timer == 0)
			{
				FP.world.removeAll();
				FP.world = new TreeWorld();
			}
			if (began)
			{
				bgButton.y -= FP.elapsed*1000;
				tuto.x +=FP.elapsed*1000;
			}
			super.update();
			play.frame = 0;
			credits.frame = 0;
			if (FP.screen.mouseX > 15 && FP.screen.mouseX < 215)
			{
				if (FP.screen.mouseY > 200 && FP.screen.mouseY < 290)
				{
					play.frame = 1;
					Clipper.over=true;
					if (Input.mouseDown) play.frame = 2;
					if (Input.mouseReleased)
					{
						began = true;
						timer = 1;
						cre = false;
					}
				}
				if (FP.screen.mouseY > 300 && FP.screen.mouseY < 390)
				{
					credits.frame = 1;
					Clipper.over = true;
					if (Input.mouseDown) credits.frame = 2;
					if (Input.mouseReleased)
					{
						cre = true;
						timer = 1;
					}
				}
			}
			
			if (cre)
			{
				bgCredits.y = (FP.screen.height - bgCredits.height) + 300 * timer;
			}
		}
		
		override public function render():void 
		{
			Draw.graphic(bg);
			Draw.graphic(tuto);
			Draw.graphic(bgButton);
			if (!began)
			{
				Draw.graphic(title);
				Draw.graphic(play);			
				Draw.graphic(credits);	
			}
			if (cre) Draw.graphic(bgCredits);
			super.render();
			Draw.graphic(fg);
			//Draw.blend = "Add";
			//light.blend = "overlay";
			//Draw.graphic(light);
				
		}
	}

}