package classes.matuto.core
{

	/*

	
		Classe responsavel pelos botoes
		de navegacao do site, botoes do menu.
	
		autor: gustavo cosme
		data:  18/maio/2011
	
	*/
	
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.utils.*;
	

	public class Button extends MovieClip
	{
		
		public  var params	: Object;
		private var url		: String; 
		private var countClick:int = 0;
		public static const SELECT			:String = "select";
		private var timer		:Timer = new Timer(400, 10); 
		private var container:MovieClip;	
		private var yAtual = 0;
		
		public function Button()
		{
			
			params = new Object();
			enableButton();
						
		}
		
		public function init():void
		{
			
			return void;
		}
		
		public function close():void
		{
			
			return void;
		}
		
		
		public function enableButton() :void
		{
			
			this.buttonMode 	= true;
			this.mouseChildren 	= true;
			this.mouseEnabled  	= true;
			
			//this.addEventListener("click", click_handle);
			//this.addEventListener("rollOver", over_handle);
			//this.addEventListener("rollOut", out_handle);
			this.addEventListener(MouseEvent.MOUSE_DOWN, down_handle);
			
		}
		
		public function enableButton2(container2:MovieClip) :void
		{
			container = container2;
			this.buttonMode 	= true;
			this.mouseChildren 	= true;
			this.mouseEnabled  	= true;
			
			//this.addEventListener("click", click_handle);
			//this.addEventListener("rollOver", over_handle);
			//this.addEventListener("rollOut", out_handle);
			container.addEventListener(MouseEvent.MOUSE_DOWN, down_handle2);
			
		}
		
		private function up_handle(e:MouseEvent):void 
		{
			Main.INSTANCE.stage.removeEventListener(MouseEvent.MOUSE_UP, up_handle);
			this.addEventListener(MouseEvent.MOUSE_DOWN, down_handle);
			
			
			if (timer.currentCount == 0)
			click();	
			
			timer.reset();

				
			up();
			out();
						
			
		}
		

		private function up_handle2(e:MouseEvent):void 
		{
			
			container.removeEventListener(MouseEvent.MOUSE_UP, up_handle2);
			container.addEventListener(MouseEvent.MOUSE_DOWN, down_handle2);
			
			
			if (timer.currentCount == 0)
			click();	
			
			timer.reset();

				
			up();
			out();
						
			
		}
		
		public function up():void 
		{
			
		}
		
		private function down_handle(e:MouseEvent):void 
		{
			this.removeEventListener(MouseEvent.MOUSE_DOWN, down_handle);
			Main.INSTANCE.stage.addEventListener(MouseEvent.MOUSE_UP, up_handle);
			timer.start();
			
			yAtual = Main.INSTANCE.stage.mouseY+10

			
			down();
			over();
		}
		
		private function down_handle2(e:MouseEvent):void 
		{
			container.removeEventListener(MouseEvent.MOUSE_DOWN, down_handle2);
			container.addEventListener(MouseEvent.MOUSE_UP, up_handle2);
			timer.start();
			
			yAtual = Main.INSTANCE.stage.mouseY

			
			down();
			over();
		}
		
		public function down():void 
		{
			
		}
		
		
		public function disableButton() :void
		{
			
			this.buttonMode 	= false;
			this.mouseChildren 	= false;
			this.mouseEnabled  	= false;
			

			this.removeEventListener(MouseEvent.MOUSE_DOWN, down_handle);
			Main.INSTANCE.stage.removeEventListener(MouseEvent.MOUSE_UP, up_handle);
			this.removeEventListener("click", click_handle);
			this.removeEventListener("rollOver", over_handle);
			//this.removeEventListener("rollOut", out_handle);
			
		}
		
		
		public function click_handle( event :MouseEvent = null ) :void
		{
			click();
		}
		
		public function over_handle( event :MouseEvent = null ) :void
		{	
			//over();	
		}
		
		public function out_handle( event :MouseEvent = null ) :void
		{
			//out();
		}
		
		public function click() :void
		{   	
			dispatchEvent(new Event(SELECT));
		}
		
		
		public function over() :void
		{
		}
		
		
		public function out() :void
		{
		}
		
		
		public  override   function set enabled( bool :Boolean ) :void
		{
			this.mouseEnabled 	    = bool;
			
			if(bool)
			enableButton();
			else
			disableButton();
			
		}
		
		
		public  override  function get enabled() :Boolean
		{
			return this.mouseEnabled;	
		}
		
		public function set setParams(_params:Object):void
		{
			params = _params;
		}
				
		public function get getParams():Object
		{
			return params;		
		}
		
		public function set setUrl(value:String):void
		{
			url = value;
		}
		
		public function get getUrl():String
		{
			return url;
		}
		
		
		
	}//end class
	
}
