package 
{
	import flash.display.Sprite;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.events.MouseEvent;
	import flash.media.Sound;

	public class Button extends Sprite 
	{
		private var back : Label;
		private var front : Label;
		private var shift : Number = 1;
		private var mouse_over : Boolean = false;
		private var func : Function;
		private var size : Number;
		
		[Embed(source="../lib/menu_click.mp3")]
        public var sound_menu_click_embed : Class;
		private var sound_menu_click : Sound = new sound_menu_click_embed() as Sound;
		
		[Embed(source="../lib/menu_move.mp3")]
        public var sound_menu_move_embed : Class;
		private var sound_menu_move : Sound = new sound_menu_move_embed() as Sound; 	
		
		public function Button(t : String, f : Function, py : Number, s : Number, c1 : uint = 0xFFFFFF, c2 : uint = 0x888888) {
			size = s;
			front = new Label(t, 0, 0, s, c1);
			back = new Label(t, 0, 0, s, c2);
			y = py;
			func = f;			
			
			addChild(back);
			addChild(front);

			x = Global.WIDTH / 2 - width / 2;
			
			buttonMode = true;
			addEventListener(MouseEvent.MOUSE_OVER, onMouseOver);
			addEventListener(MouseEvent.MOUSE_OUT, onMouseOut);
			addEventListener(MouseEvent.CLICK, onMouseClick);
		}
		
		private function onMouseOver(e : MouseEvent):void { 
			if (!mouse_over) sound_menu_move.play(); 
			mouse_over = true; 
		}
		private function onMouseOut(e : MouseEvent):void { mouse_over = false; }
		private function onMouseClick(e : MouseEvent):void { sound_menu_click.play(); func(); }
		
		public function Update():void {
			if (mouse_over){
				if (shift > 0) shift -= 0.1 * size;
			}else
				if (shift < 1) shift += 0.1 * size;
				
			front.x = back.x - shift * 1.5 * size;
			front.y = back.y - shift * 1.5 * size;
		}
	}
	
}