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,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,
	0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,0,0,
	0,0,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,0,0,
	0,1,0,0,0,1,0,0,0,1,0,0,0,0,1,0,0,0,1,0
]
];

var CBlitz=Class.create(
{
	initialize: function()
	{
		this.container=$('container');

		this.bomb=document.createElement('div');
		this.bomb.className='bomb';
		this.bomb.style.display='none';
		this.container.appendChild(this.bomb);

		this.plane=document.createElement('div');
		this.plane.className='plane';
		this.container.appendChild(this.plane);

		this.explosion=document.createElement('div');
		this.explosion.className='explosion';
		this.explosion.style.display='none';
		this.container.appendChild(this.explosion);

		this.levelData=null;
		this.render();
//		this.newGame();
	},
	newGame: function()
	{
		this.levelData=null;
//		$('menu').style.display='none';
		new Effect.Fade('menu', {afterFinish: this.preStartLevel.bind(this)});
		$('container').style.display='';
		this.removeTowers();
		this.towers=[];
		this.level=0;
		this.lives=3;
		this.updateLives();
		this.render();
	},
	updateLives: function()
	{
		if (this.lives==3)
		{
			$('life_1').style.display='';
			$('life_2').style.display='';
			$('life_3').style.display='';
		}
		if (this.lives==2)
		{
			$('life_1').style.display='none';
			$('life_2').style.display='';
			$('life_3').style.display='';
		}
		if (this.lives==1)
		{
			$('life_1').style.display='none';
			$('life_2').style.display='none';
			$('life_3').style.display='';
		}
		if (this.lives<1)
		{
			$('life_1').style.display='none';
			$('life_2').style.display='none';
			$('life_3').style.display='';
		}
	},
	preStartLevel: function()
	{
		if (this.timer)
		{
			clearInterval(this.timer);
			this.timer=null;
		}
		$('level').innerHTML="Level " + (this.level+1);
		this.x=320;
		this.y=32;
		this.removeTowers();
		this.towers=[];
		this.renderLevel();
		this.bombDropping=false;
		this.update();
		$('level_indicator').innerHTML=(this.level+1);
		new Effect.Appear("level_indicator", {to: 0.3});
		setTimeout(this.preStartLevel2.bind(this), 2000);
//		startLevel();
	},
	nextLevel: function()
	{
		this.level++;
		if (this.level==10)
		{
			alert("Well done! You have completed the first 10 levels of Blitz!");
			alert("More levels will be available soon!");
			this.gameOver();
			return;
		}
		this.preStartLevel();
	},
	restartLevel: function()
	{
		if (this.timer)
		{
			clearInterval(this.timer);
			this.timer=null;
		}
		$('level').innerHTML="Level " + (this.level+1);
		this.x=320;
		this.y=32;
		this.bombDropping=false;
		this.update();
		$('level_indicator').innerHTML=(this.level+1);
		new Effect.Appear("level_indicator", {to: 0.3});
		setTimeout(this.preStartLevel2.bind(this), 2000);
	},
	preStartLevel2: function()
	{
		new Effect.Fade("level_indicator",{afterFinish: this.startLevel.bind(this)});
	},
	startLevel: function()
	{
		if (this.timer)
		{
			clearInterval(this.timer);
			this.timer=null;
		}
		this.timer=setInterval(this.update.bind(this), 250);
	},
	clearExplosionTimer: function()
	{
		if (this.explosionTimer)
		{
			clearTimeout(this.explosionTimer);
			this.explosionTimer=null;
		}
	},
	setExplosionTimer: function()
	{
		this.clearExplosionTimer();	
		this.explosionTimer=setTimeout(this.hideExplosion.bind(this),3000);
	},
	hideExplosion: function()
	{
		this.explosion.style.display='none';
	},
	gameOver: function()
	{
		clearInterval(this.timer);
		this.timer=null;
		new Effect.Appear("menu");
	},
	removeTowers: function()
	{
		var loopX;
		var loopY;
		var ptr=0;
		if (!this.towers)
		{
			return;
		}
		
		for (loopY=0; loopY<20; loopY++)
		{
			for (loopX=0; loopX<20; loopX++)
			{
				if (this.towers[(loopY*20)+loopX])
				{
					$('container').removeChild(this.towers[ptr]);
				}
			ptr++;
			}
		}
	},
	renderLevel: function()
	{
		var loopX;
		var loopY;
		var div;
		var x=0;
		var y=0;
		this.levelData=Data[this.level].slice();
		for (loopY=0; loopY<20; loopY++)
		{
			x=0;
			for (loopX=0; loopX<20; loopX++)
			{
				if (this.levelData[(loopY*20)+loopX]!=0)
				{
					div=document.createElement('div');
					div.className='tower_block';
					div.style.left=x + 'px';
					div.style.top=y + 'px';
					this.towers[(loopY*20)+loopX]=div;
					$('container').appendChild(div);
				}
				x+=16;
			}
			y+=16;
		}
	},
	render: function()
	{
	},
	update: function()
	{
		var ptr=((this.y/16)*20)+(this.x/16);
		this.position();
		if (this.levelData[ptr]!=0)
		{
			this.crash();
			return;
		}
		if (this.bombDropping)
		{
			this.updateBomb();
		}
		this.x-=16;
		if (this.x<0)
		{
			this.y+=16;
			this.x+=320;
		}
	},
	crash: function()
	{
		this.towerBlockHit(this.x/16,this.y/16);
//		this.y=32;
//		this.x=320;
		this.lives--;
		this.updateLives();
		if (this.lives==0)
		{
			alert("Game Over!");
			this.gameOver();
		}
		else
		{
			this.restartLevel();
		}
	},
	dropBomb: function()
	{
		if (this.bombDropping)
		{
			return;
		}
		this.bombX=this.x;
		this.bombY=this.y+16;
		this.bomb.style.left=this.bombX + 'px';
		this.bomb.style.top=this.bombY + 'px';
		this.bomb.style.display='';
		this.bombDropping=true;
	},
	updateBomb: function()
	{
		var x,y;
		x=this.bombX/16;
		y=this.bombY/16;
		this.bomb.style.left=this.bombX + 'px';
		this.bomb.style.top=this.bombY + 'px';
		
		if (this.levelData[(y*20)+x]!=0)
		{
			this.towerBlockHit(x,y);
			this.bombDone();
			if (this.isLevelClear())
			{
				this.nextLevel();
			}
			return;
		}
		
		this.bombY+=16;
		if (this.bombY>=320)
		{
			this.bombDone();
		}
	},
	isLevelClear: function()
	{
		var loop;
		for (loop=0; loop<this.towers.length; loop++)
		{
			if (this.towers[loop])
			{
				return false;
			}
		}
		return true;
	},
	towerBlockHit: function(x,y)
	{
		var ptr=(y*20)+x;
		this.levelData[ptr]=0;
		$('container').removeChild(this.towers[ptr]);
		this.towers[ptr]=null;
		this.explosion.style.left=(x*16) + "px";
		this.explosion.style.top=(y*16) + "px";
		this.explosion.style.display='';
		this.setExplosionTimer();
	},
	bombDone: function()
	{
		this.bombDropping=false;
		this.bomb.style.display='none';
	},
	position: function()
	{
		this.plane.style.left=this.x + 'px';
		this.plane.style.top=this.y + 'px';
	}
});