(function(window){	function SpaceInvaders(canvasID, imgsrcSpaceship, imgsrcAlien)	{		canvas	= document.getElementById(canvasID);		context	= canvas.getContext('2d');		stage	= new Stage(canvas);		Registry.set('STAGE_WIDTH', canvas.width);		Registry.set('STAGE_HEIGHT', canvas.height);		Registry.set('CONTEXT', context);		this.imgsrcSpaceship	= imgsrcSpaceship;		this.imgsrcAlien		= imgsrcAlien;		this.initialize();	}	SpaceInvaders.prototype = new Container();		SpaceInvaders.prototype.imgsrcSpaceship	= '';		SpaceInvaders.prototype.imgsrcAlien		= '';		// Signals		SpaceInvaders.prototype.completed		= new signals.Signal();		// Constructor:		SpaceInvaders.prototype.Container_initialize = SpaceInvaders.prototype.initialize;	// Unique to avoid overiding base class		/**		* INIT METHODS		*/		SpaceInvaders.prototype.initialize = function()		{			this.Container_initialize();			this.initLines();			this.initScoreBoard();			this.loadSpaceshipBitmap();		}		SpaceInvaders.prototype.initLines = function()		{			var line1	= new HorisontalLine(Registry.get('STAGE_WIDTH'), 1);			stage.addChild(line1);			var line2	= new HorisontalLine(Registry.get('STAGE_WIDTH'), 1);			line2.y		= 40;			stage.addChild(line2);			var line3	= new HorisontalLine(Registry.get('STAGE_WIDTH'), 1);			line3.y		= Registry.get('STAGE_HEIGHT') - 1;			stage.addChild(line3);		}		SpaceInvaders.prototype.initScoreBoard = function()		{			scoreBoard				= new ScoreBoard();			scoreBoard.x			= Registry.get('STAGE_WIDTH') - 10;			scoreBoard.y			= 30;			scoreBoard.mouseEnabled	= false;			stage.addChild(scoreBoard);		}		SpaceInvaders.prototype.loadSpaceshipBitmap = function()		{			var _this	= this;			var loader	= new BitmapLoader(this.imgsrcSpaceship);			loader.completed.addOnce(function(image){_this.onSpaceshipBitmapLoaded(image);});			loader.load();		}		SpaceInvaders.prototype.onSpaceshipBitmapLoaded = function(image)		{			spaceship				= new Spaceship(image);			spaceship.x				= Math.round((Registry.get('STAGE_WIDTH') - spaceship.width) / 2);			spaceship.y				= Math.round(Registry.get('STAGE_HEIGHT') - spaceship.height - 15);			spaceship.offset		= new Point(spaceship.x, spaceship.y);			spaceship.mouseEnabled	= false;			stage.addChild(spaceship);			this.loadAlienBitmap();		}		SpaceInvaders.prototype.loadAlienBitmap = function()		{			var _this	= this;			var loader	= new BitmapLoader(this.imgsrcAlien);			loader.completed.addOnce(function(image){_this.onAlienBitmapLoaded(image);});			loader.load();		}		SpaceInvaders.prototype.onAlienBitmapLoaded = function(image)		{			aliens				= new Aliens(image, new Point(25,40));			aliens.mouseEnabled	= false;			stage.addChild(aliens);			this.initGameController();		}		SpaceInvaders.prototype.initGameController = function()		{			var _this		= this;			gameController	= new GameController(stage, spaceship, aliens, scoreBoard, new KeyController());			gameController.completed.add(function(score){_this.onGameCompleted(score);});			startBtn			= new GenericButton('START SPIL!');			startBtn.x			= Registry.get('STAGE_WIDTH')/2;			startBtn.y			= Registry.get('STAGE_HEIGHT')/2 + 100;			startBtn.onClick	= this.start;			stage.addChild(startBtn);		}		/**		* SIGNAL METHODS		*/		SpaceInvaders.prototype.start = function(e)		{			this.onClick	= null;	// this == the btn clicked			this.parent.removeChild(this);			gameController.restart();		}		SpaceInvaders.prototype.onGameCompleted = function(score)		{			playAgainBtn			= new GenericButton('SPIL IGEN!');			playAgainBtn.x			= Registry.get('STAGE_WIDTH')/2;			playAgainBtn.y			= Registry.get('STAGE_HEIGHT')/2;			playAgainBtn.onClick	= this.start;			stage.addChild(playAgainBtn);			this.completed.dispatch(score);		}	window.SpaceInvaders = SpaceInvaders;}(window));
