package game.GameMenu
{
	import flash.display.Bitmap;
	import flash.events.GameInputEvent;
	import flash.events.MouseEvent;
	import flinjin.Flinjin;
	import flinjin.graphics.Layer;
	import flinjin.graphics.Sprite;
	import flinjin.sound.FlinjinSoundCollection;
	
	/**
	 * ...
	 * @author Michael Miriti
	 */
	public class GameMenu extends Layer
	{
		[Embed(source="../../assets/menu/menu_skrool_tail.jpg")]
		private static var _scrollBg:Class;
		
		[Embed(source="../../assets/menu/menu_statik.png")]
		private static var _menuStatic:Class;
		
		[Embed(source="../../assets/menu/start_btn.png")]
		private static var _startBtnBmp:Class;
		
		[Embed(source="../../assets/menu/sounds_btn.png")]
		private static var _soundsBmp:Class;
		
		[Embed(source="../../assets/menu/music_btn.png")]
		private static var _musicBmp:Class;
		
		[Embed(source="../../assets/menu/color_btn.png")]
		private static var _colorBmp:Class;
		
		private var _startBtnSprite:GameMenuItem = new GameMenuItem(new _startBtnBmp() as Bitmap, null, true, 234, 118);
		
		private var _backgroundScroll:Sprite = new Sprite(new _scrollBg() as Bitmap);
		
		public var _main:Main;
		
		private var _movingState:Boolean = false;
		private var _menuStaticSprite:Sprite = new Sprite(new _menuStatic() as Bitmap);
		private var _sp:Number = 20;
		private var _soundsBtn:GameMenuItemSwitch = new GameMenuItemSwitch(new _soundsBmp(), null, true, 99, 99);
		private var _musicBtn:GameMenuItemSwitch = new GameMenuItemSwitch(new _musicBmp(), null, true, 99, 99);
		private var _colorBtn:GameMenuItemSwitch = new GameMenuItemSwitch(new _colorBmp(), null, true, 99, 99);
		
		override public function Move():void
		{
			
			if (_movingState)
			{
				_backgroundScroll.x -= _sp;
				_startBtnSprite.x -= _sp;
				_menuStaticSprite.x -= _sp;
				_soundsBtn.x -= _sp;
				_musicBtn.x -= _sp;
				_colorBtn.x -= _sp;
				
				if (_backgroundScroll.x <= -480)
				{
					_main.gotoGame();
				}
			}
			else
			{
				_backgroundScroll.scrollY += 0.5;
			}
			
			super.Move();
		}
		
		public function GameMenu()
		{
			super(Flinjin.sceneWidth, Flinjin.sceneHeight);
			
			_backgroundScroll.repeatY = true;
			addSprite(_backgroundScroll);
			addSprite(_menuStaticSprite);
			
			_startBtnSprite.addEventListener(MouseEvent.MOUSE_DOWN, onStartClick);
			addSprite(_startBtnSprite, 210, 160);
			
			addSprite(_soundsBtn, 170, 20);
			addSprite(_musicBtn, 270, 20);
			addSprite(_colorBtn, 370, 20);
			
			_soundsBtn.addEventListener(MouseEvent.MOUSE_DOWN, onSoundBtn);
			_musicBtn.addEventListener(MouseEvent.MOUSE_DOWN, onMusicBtn);
			_colorBtn.addEventListener(MouseEvent.MOUSE_DOWN, onColorBtn);
		}
		
		private function onSoundBtn(e:MouseEvent):void
		{
			if (_soundsBtn.isOn())
			{
				FlinjinSoundCollection.enabled = true;
				if (_musicBtn.isOn())
				{
					_main.sndMainTheme.play();
				}
			}
			else
			{
				FlinjinSoundCollection.enabled = false;
			}
		}
		
		private function onMusicBtn(e:MouseEvent):void
		{
			if (_musicBtn.isOn())
			{
				_main.sndMainTheme.play();
			}
			else
			{
				_main.sndMainTheme.stop();
			}
		}
		
		private function onColorBtn(e:MouseEvent):void
		{
			if (_colorBtn.isOn())
			{
				_main.Screen.MainLayer.setColorMults(1.5, 1.2, 0.7);
			}
			else
			{
				_main.Screen.MainLayer.setColorMults(1, 1, 1);
			}
		}
		
		private function onStartClick(e:MouseEvent):void
		{
			if (!_movingState)
			{
				_movingState = true;
			}
		}
	
	}

}