package game.GameMain
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flinjin.Flinjin;
	import flinjin.graphics.Sprite;
	
	/**
	 * ...
	 * @author Michael Miriti
	 */
	public class Background extends Sprite
	{
		[Embed(source="../../assets/back/back_1.jpg")]
		private static var _BackDeepest:Class;
		private var _BackDeepestBMP:Bitmap = new _BackDeepest();
		
		[Embed(source="../../assets/back/back_2.png")]
		private static var _BackDeeper:Class;
		private var _BackDeeperBMP:Bitmap = new _BackDeeper();
		
		private var _Layer1:BitmapData = new BitmapData(480, 640);
		private var _Layer2:BitmapData = new BitmapData(480, 640);
		
		private var _scrollY:Number = 0;
		private var _scrollY2:Number = 0;
		
		override public function get scrollY():Number
		{
			return super.scrollY;
		}
		
		override public function set scrollY(value:Number):void
		{
			_scrollY += value * 0.2;
			_scrollY = _scrollY % (1280);
			var _p:int = 1280 - 640 - _scrollY;
			if (_p < 0)
			{
				_Layer1.copyPixels(_BackDeepestBMP.bitmapData, new Rectangle(0, 1280 + _p, 480, 640), new Point());
			}
			_Layer1.copyPixels(_BackDeepestBMP.bitmapData, new Rectangle(0, _p, 480, 640), new Point());
			
			_scrollY2 += value * 0.6;
			_scrollY2 = _scrollY2 % (1280);
			_p = 1280 - 640 - _scrollY2;
			if (_p < 0)
			{
				_Layer2.copyPixels(_BackDeeperBMP.bitmapData, new Rectangle(0, 1280 + _p, 480, 640), new Point());
			}
			_Layer2.copyPixels(_BackDeeperBMP.bitmapData, new Rectangle(0, _p, 480, 640), new Point());
			
			_current_bitmap.draw(_Layer1);
			_current_bitmap.draw(_Layer2);
		}
		
		override protected function _Draw(surface:BitmapData, shiftVector:Point = null):void
		{
			super._Draw(surface, shiftVector);
		}
		
		public function Background()
		{
			var _bmp:Bitmap = new Bitmap(new BitmapData(Flinjin.sceneWidth, Flinjin.sceneHeight), "auto", Sprite.Smoothing);
			super(_bmp);
			
			scrollY = 0;
		}
	
	}

}