package classes
{
	import flash.events.Event;
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.events.FocusEvent;
	import flash.net.URLRequest;
	import flash.system.LoaderContext;
	import scaleform.clik.core.UIComponent;
	import scaleform.clik.data.ListData;
	import scaleform.clik.interfaces.IListItemRenderer;

	public class OBJ_ImageBox extends MovieClip 
	{
		// Protected Properties:
		protected var _data:Object;
		protected var _loadedImage:String;

		// UI Elements:
		public var gfx_image:MovieClip;
		public var imageLoader:Loader;

		public function OBJ_ImageBox()
		{
			super();
			_loadedImage = "";
		}
		
		public var SET_ImageDataString:Function = function( newString:String ):void
		{
			var newData = new Object;
			newData.image = newString;

			_data = newData;
		}

		public var SET_ImageData:Function = function( newData:Object ):void
		{
			_data = newData;
		}

		public var ANIM_ImageBox_Show:Function = function ():void 
		{			
			if (_data)
			{
				if (_data.image && (_loadedImage != _data.image))
				{
					if ((imageLoader == null))
					{
						imageLoader = new Loader;
						gfx_image.addChild(imageLoader);
						trace( "new Image loader created");
					}

					imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,ShowNewImage,false,0,true);
					
					var url:URLRequest = new URLRequest(_data.image);
					var context:LoaderContext = new LoaderContext(false,null);
					imageLoader.load(url,context);					

					trace( "new Image created");
				}
				else
				{
					ShowNewImage();
				}
			}
		}		
		
		
		protected function ShowNewImage():void
		//protected function ShowNewImage( evt:Event ):void
		{			
			//	NOTE::AREP:: Ideally, we should be showing images at 100% resolution. 
			//		I should make sizing to fit be a debug override.
			_loadedImage = _data.image;
		
			if( true )//_data.isStretched )
			{
				imageLoader.width = 300; 
				imageLoader.height = 300; 
			}

			imageLoader.x = -imageLoader.width * 0.5; 
			imageLoader.y = -imageLoader.height * 0.5; 
			
			gotoAndStop("FRAME_SHOW");
		}
		
		public var ANIM_ImageBox_Hide:Function = function ():void 
		{
			gotoAndPlay("FRAME_HIDE");
		}

		override public function toString():String
		{
			return "[MenuKit DifficultyItemRenderer " + name + "]";
		}

	}
}