//ToolTip XPRESION
//Todos los derechos reservados 2011
//Por: Juan Carlos Sevillano
//www.xpresion-ec.com

package clases
{
	import flash.display.MovieClip;
	import flash.text.*;
	import flash.display.Shape;
	import flash.filters.DropShadowFilter;
	import flash.display.GradientType;
	import flash.geom.Matrix;
	import flash.events.MouseEvent;
	import flash.events.Event;

	public class toolTipXpresion extends MovieClip
	{
		var tool:MovieClip = new MovieClip();
		var cajaT:TextField = new TextField();
		var formato:TextFormat = new TextFormat();
		var texto:String;
		var clip;
		var pariente:MovieClip;
		var recDib:Shape = new Shape();
		var triangulo:MovieClip = new MovieClip();
		var triDib:Shape = new Shape();
		var alto:int;
		var ancho:int;
		var sombra:DropShadowFilter = new DropShadowFilter(3,45,0,0.7,6,6,1,3,false,false,false);
		var tipo:String = GradientType.LINEAR;
		var colores:Array = [0xFFFFFF,0xcccccc];
		var alfas:Array = [1,1];
		var relacion:Array = [0,255];
		var matriz:Matrix = new Matrix();
		var cajaAncho:Number = 0;
		var cajaAlto:Number;
		var rotacionDegrade:Number = Math.PI / 2;// 90° 
		var tx:Number = 0;
		var ty:Number = 0;

		var incAlfa:Number = 0.15;
		public function toolTipXpresion(botonPasado,textoPasado:String)
		{

			clip = botonPasado;
			texto = textoPasado;
			pariente = MovieClip(clip.parent);
			
			formato.align = TextFormatAlign.CENTER;
			formato.font = "Tahoma";
			
			//cajaT.embedFonts = true
			cajaT.antiAliasType = "advanced";
			cajaT.autoSize = TextFieldAutoSize.LEFT;
			cajaT.x = 5;
			cajaT.y = 5;
			//cajaT.border = true
			cajaT.multiline = true;
			cajaT.htmlText = texto;
			cajaT.type = "dynamic";
			cajaT.selectable = false;
			cajaT.mouseWheelEnabled = false;
			cajaT.setTextFormat(formato);
			alto = cajaT.height + 10;
			ancho = cajaT.width+12;
			
			cajaAlto = alto;
			cajaAncho = alto;
			//recDib.graphics.lineStyle(1.2,0x999999)
			matriz.createGradientBox(cajaAncho, cajaAlto, rotacionDegrade, tx, ty);
			recDib.graphics.beginGradientFill(tipo,colores,alfas,relacion,matriz);
			recDib.graphics.drawRoundRect(0,0,ancho,alto,15,15);
			recDib.graphics.endFill();
			//triDib.graphics.lineStyle(1.2,0x999999);
			triDib.graphics.beginFill(colores[1],1);
			triDib.graphics.moveTo(-7,0);
			triDib.graphics.lineTo(7,0);
			triDib.graphics.lineTo(0,10);
			triDib.graphics.lineTo(-7,0);
			triDib.graphics.endFill();
			triangulo.addChild(triDib);
			triangulo.y = alto-1;
			triangulo.x = ancho/2;
			
			tool.addChild(recDib);
			tool.addChild(cajaT);
			tool.addChild(triangulo);
			tool.x = clip.x;
			tool.y = clip.y 
			//tool.filters = [borde]
			tool.filters = [sombra];
			
			tool.mouseChildren = false;
			tool.buttonMode = false;
			tool.mouseEnabled = false;
			tool.useHandCursor = false;
			tool.alpha = 0;
			
			clip.addEventListener(MouseEvent.ROLL_OVER,activar);
			clip.addEventListener(MouseEvent.ROLL_OUT,desactivar);
		}
		public function activar(event)
		{
			tool.alpha = 0;
			
			var toolAncho = tool.width;
			var clipAncho = clip.width;
			var toolAlto = tool.height;
			tool.x = clip.x + clipAncho/2 - toolAncho/2;
			
			if ((tool.x+toolAncho) > (pariente.stage.stageWidth-50))
			{

				var difXE:int = tool.x + toolAncho - pariente.stage.stageWidth - 50;
				//trace(difXE)
				tool.x = tool.x - difXE - 60;
			}
			if (tool.x < 10){
				tool.x = 10
				}

			tool.y = clip.y - toolAlto + 10
			pariente.addChild(tool);
			triangulo.x = tool.mouseX;
			if (triangulo.x < 15)
			{
				triangulo.x = 15;
			}
			if (triangulo.x> (ancho-15))
			{
				triangulo.x = ancho - 15;
			}
			tool.addEventListener(Event.ENTER_FRAME,aumento);
		}
		public function desactivar(event)
		{
			tool.addEventListener(Event.ENTER_FRAME,disminucion);
		}
		public function aumento(event)
		{
			tool.alpha +=  incAlfa;
			if (tool.alpha > 1)
			{
				tool.alpha = 1;
				tool.removeEventListener(Event.ENTER_FRAME,aumento);
			}
		}
		public function disminucion(event)
		{
				tool.removeEventListener(Event.ENTER_FRAME,disminucion);
				pariente.removeChild(tool);
		
		}
	}
}