import com.netentertainment.tablegames.th1h.event.THInGameEvent;
import mx.utils.Delegate;
/******************************************************************************
 * TODO: Add a description of this class.
 * Author: Bjarne Grönnevik
 ******************************************************************************/
class PromoView extends MovieClip
{
	private var promoCount:Number;
	private var picker_animation:MovieClip;
	private var picker:MovieClip;
	private var detector:Button;
	/*private var transperant1:Button;
	private var transperant2:Button;
	private var transperant3:Button;
	private var transperant4:Button;
	private var transperant5:Button;
	private var transperant6:Button;*/
	private var intervalId:Number = undefined;
	private var shownAsBaraDen:Boolean = false;
	private var promoIndex:Number = 1;
	private var tiki:MovieClip;
	/**************************************************************************
	 * TODO: Document constructor PromoView
	 **************************************************************************/
	public function PromoView() 
	{
		promoCount = 0;
	}
	
	/**************************************************************************
	 * TODO: Document function onLoad
	 **************************************************************************/
	private function onLoad() : Void
	{
		trace("PromoView.onLoad: " + picker_animation.picker.prev);
		Button(picker_animation.picker.next).onRelease = Delegate.create(this, inreaseIndex);
		Button(picker_animation.picker.prev).onRelease = Delegate.create(this, decreaseIndex);
		
		setupButtons();
	}
	
	private function setupButtons() : Void
	{
		for(var i:Number = 1; true; i++)
		{
			var temp:Button = picker_animation.picker["button" + i];
			if(!temp)
			{
				break;
			}
			temp.onRelease = Delegate.create(this, this["showPromo" + i]);
			promoCount = i;
			trace(temp + " is number " + promoCount);
		}
	}
	
	private function inreaseIndex() :Void
	{
		clearInterval(intervalId);
		intervalId = setInterval(this, "testForClose", 3000);
		
		trace("PromoView.inreaseIndex()");
		gotoFrameLabel(1);
	}
	
	private function decreaseIndex() :Void
	{
		clearInterval(intervalId);
		intervalId = setInterval(this, "testForClose", 3000);
		
		trace("PromoView.decreaseIndex()");
		gotoFrameLabel(-1);
	}
	
	private function showPromo1() : Void
	{
		gotoAndPlay("_" + 1);
	}
	private function showPromo2() : Void
	{
		gotoAndPlay("_" + 2);
	}
	private function showPromo3() : Void
	{
		gotoAndPlay("_" + 3);
	}
	private function showPromo4() : Void
	{
		gotoAndPlay("_" + 4);
	}
	private function showPromo5() : Void
	{
		gotoAndPlay("_" + 5);
	}
	private function showPromo6() : Void
	{
		gotoAndPlay("_" + 6);
	}
	
	private function showPromo7() : Void
	{
		gotoAndPlay("_" + 7);
	}
	
	private function showPromo8() : Void
	{
		gotoAndPlay("_" + 8);
	}
	
	private function showPromo9() : Void
	{
		gotoAndPlay("_" + 9);
	}
	
	private function showPromo10() : Void
	{
		gotoAndPlay("_" + 10);
	}
	
	private function gotoFrameLabel(steps:Number) :Void
	{
		var tmpNum:Number = promoIndex + steps;
		/*trace (myVariable)*/
		if (tmpNum < 1)
		{
			tmpNum = promoCount;
		} 
		else
		{
			if (tmpNum > promoCount)
			{
				tmpNum = 1;
			}
		}
		gotoAndPlay("_" + tmpNum);
	}
	
	private function gotoPickerLabel() :Void
	{
		trace("active"+promoIndex);
		picker_animation.picker.gotoAndStop("active"+promoIndex);

	}
	
	/**************************************************************************
	 * TODO: Document function onMouseMove
	 **************************************************************************/
	private function onMouseMove() : Void
	{
		if(!shownAsBaraDen)
		{
			trace("PromoView.animate() : Show");
			picker_animation.gotoAndPlay('picker_in');
			shownAsBaraDen = true;
		}
		
		clearInterval(intervalId);
		intervalId = setInterval(this, "testForClose", 3000);
	}
	
	/**************************************************************************
	 * TODO: Document function testForClose
	 **************************************************************************/
	private function testForClose() : Void
	{
		trace("PromoView.testForClose()");
		
		picker_animation.gotoAndPlay('picker_out');
		trace("PromoView.testForClose: Delete interval: " + intervalId);
		shownAsBaraDen = false;
		
		clearInterval(intervalId);
	}
}