<?xml version="1.0" encoding="UTF-8"?>
<Module>
	<ModulePrefs author="LabPixies"
	author_email="info@labpixies.com"
	description="__MSG_description__"
	screenshot="http://www.labpixies.com/campaigns/invaders/images/screenshot.gif"
	title="__MSG_gTitle__"
	title_url="http://www.labpixies.com"
	thumbnail="http://www.labpixies.com/campaigns/invaders/images/thumbnail.jpg" height="320" render_inline="never">
		
    <Locale messages="http://www.labpixies.com/campaigns/invaders/i19/all_all.xml"/>
		<Locale lang="es" messages="http://www.labpixies.com/campaigns/invaders/i19/es_all.xml"/>
    <Locale lang="de" messages="http://www.labpixies.com/campaigns/invaders/i19/de_all.xml"/>
    <Locale lang="fr" messages="http://www.labpixies.com/campaigns/invaders/i19/fr_all.xml"/>
    <Locale lang="it" messages="http://www.labpixies.com/campaigns/invaders/i19/it_all.xml"/>
    <Locale lang="ja" messages="http://www.labpixies.com/campaigns/invaders/i19/ja_all.xml"/>
    <Locale lang="nl" messages="http://www.labpixies.com/campaigns/invaders/i19/nl_all.xml"/>
    <Locale lang="pl" messages="http://www.labpixies.com/campaigns/invaders/i19/pl_all.xml"/>
    <Locale lang="pt-PT" messages="http://www.labpixies.com/campaigns/invaders/i19/pt_all.xml"/>
    <Locale lang="pt-BR" messages="http://www.labpixies.com/campaigns/invaders/i19/pt_all.xml"/>
    <Locale lang="zh-CN" messages="http://www.labpixies.com/campaigns/invaders/i19/zh_cn_all.xml"/>
    <Locale lang="iw" messages="http://www.labpixies.com/campaigns/invaders/i19/he_all.xml"/>
    
		<Require feature="analytics"/>
	</ModulePrefs>
	<Content type="html">
		<![CDATA[
			<title>Invaders</title>
			
			<meta name="keywords" content="LabPixies, Shooter, Invaders, game, Gadget, Widget, Cool, Fun">
			<meta name="description" content="__MSG_description__">
			
			
			<!-- Invaders Module
				Design & Code: LabPixies
				All subsequent code and resources used are proprietary of LabPixies unless directly stated otherwise.
				Copyright (C) 2008 LabPixies.    
				www.labpixies.com
			
				This work is licensed under the Creative Commons Attribution-NonCommercial-NoDerivs 2.5 License.
				To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-nd/2.5/ or
				send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.
			-->
			
			
			<style type="text/css">
			<!--
			
			.style1 {
				font-size: 1px;
			}
			.statisticsItems {
				font-family: Arial, Helvetica, sans-serif;
				font-size: 12px;
				Color: #000000;
			}
			
			.invadorEXstyle {
				width:11px;
				height:10px;
				overflow:hidden;
			}
			
			.gameOverItems {
				font-family: Arial, Helvetica, sans-serif;
				font-size: 13px;
				cursor:pointer;
				text-decoration: none;
			}
			
			-->
			</style>
			
<!-- PUT THIS TAG IN THE head SECTION -->
<script type="text/javascript" src="http://partner.googleadservices.com/gampad/google_service.js">
</script>
<script type="text/javascript">
GS_googleAddAdSenseService("ca-pub-8123415297019784");
GS_googleEnableAllServices();
</script>
<script type="text/javascript">
GA_googleAddSlot("ca-pub-8123415297019784", "invaders_txt");
</script>
<script type="text/javascript">
GA_googleFetchAds();
</script>
<!-- END OF TAG FOR head SECTION -->

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
<script src="http://www.google-analytics.com/ga.js" type="text/javascript"></script> 
			
<script type="text/javascript">
	var _gadgetID=43;
  var $lp=jQuery.noConflict();

	var mSOUND = _IG_GetCachedUrl("http://cdn.labpixies.com/infra/js/soundmanager2-jsmin.js");
	document.write('<scr'+'ipt type="text/javascript" src="'+mSOUND+'"></scr'+'ipt>');
</script>
<!--[if IE 6]>
<script type="text/javascript">
	try {//IE fix, causes it to automatically cache background image
		document.execCommand("BackgroundImageCache", false, true);
	}
	catch(e){
	}
</script>
<![endif]-->
<script type="text/javascript">

WIDTH = 260; //the width of the screen
ROW_NUM = 5; //number of lines of invaders
COL_NUM = 11; // number of invaders in one line
INVADORS_NUM = ROW_NUM*COL_NUM; // totale number of invaders
MAX_TANK_WEAPON_NUM = 2; 
INVADORS_WEAPON_NUM = 15;
INV_WIDTH = 11;
INV_HEIGHT = 10;

var IMAGES_BASE="http://cdn.labpixies.com/campaigns/invaders/images/";

//envirnment varibles
var topLeftCorner;//the top left corner of the game
var invBorderRight; // the absolute right border
var invBorderLeft;// the absolute left border
var invBorderBottom;// the absolute bottom border
var gameLevel; 
var invRowsDown;


var tankWeaponNum = 1;
var invadorsArr = new Array(INVADORS_NUM);
var tankWeapon = new Array(MAX_TANK_WEAPON_NUM);
var invadorWeapon = new Array(INVADORS_WEAPON_NUM);

var gameInst;

function Invadors() {

	var visualElement = null;
	var top;
	var left;
	var direction = 1;	
	
	this.create = function() {
		
		var row,col,i;
		
		visualElement = document.getElementById("invadorsTbl");
		top = topLeftCorner.top+30;
		left = topLeftCorner.left+11;
		visualElement.style.top = top+"px";
		visualElement.style.left = left+"px";
		
		i = 0;
		for (row=0;row<ROW_NUM; row++) {
			for (col=0;col<COL_NUM; col++) {
				invadorsArr[i] = new Invador(i, row, 5 + row*15, 5 + col*16, row, col);
				i++;
			}
		}
		
		for (i=0;i<INVADORS_WEAPON_NUM;i++) {
			invadorWeapon[i] = new InvadorWeapon();
		}	
	}
	
	this.init = function() {
	
		invRowsDown = 0;
		
		top = topLeftCorner.top+20+10*gameLevel;
		left = topLeftCorner.left+11;
		visualElement.style.top = top+"px";
		visualElement.style.left = left+"px";
		visualElement.style.visibility = "visible";
		
		var i;
		for (i=0;i<INVADORS_NUM;i++) {
			invadorsArr[i].show();
		}		
		
		for (i=0;i<INVADORS_WEAPON_NUM;i++) {
			invadorWeapon[i].hide();
		}
		
		direction = 1;
	}
	
	this.step = function() {
		var i;
		var numInvadorLiving = 0;
		var shouldStepDown = false;
		for (i=0;i<INVADORS_NUM; i++) {
			
			if (!invadorsArr[i].isAvailable()) {
				
				//going right check border
				if (direction == 1) {
					if (invadorsArr[i].isOnRightBorder(left)) {
						top = top + 10;
						direction = -1;
						visualElement.style.top = top+"px";
						if (this.checkInvadorWin()) return;
						invRowsDown++;
						shouldStepDown = true;
						break;
					}
				}//going left check Border
				else {
					if (invadorsArr[i].isOnLeftBorder(left)) {
						top = top + 10;
						direction = 1;
						visualElement.style.top = top+"px";
						if (this.checkInvadorWin()) return;
						invRowsDown++;
						shouldStepDown = true;
						break;
					}
				}
			}
		}
		if (!shouldStepDown) {
			left = left + 3*direction;
			visualElement.style.left = left+"px";
		}
		
		for (i=0;i<INVADORS_NUM; i++) {			
			if (!invadorsArr[i].isAvailable())				
				numInvadorLiving++;
		}
		//move the invadorsArr
		var rnd;
		for (i=0;i<INVADORS_NUM; i++) {
			if (!invadorsArr[i].isAvailable()) {
				invadorsArr[i].step();
				rnd = Math.random()*(numInvadorLiving*10);
				if (rnd<1) {
					invadorsArr[i].dropBomb(top,left);
				}
			}
		}
		
		if (numInvadorLiving == 0) {
			gameInst.nextLevel();
		}
	}
	
	this.checkInvadorWin = function() {
	
		for (var i=0;i<INVADORS_NUM; i++) {
			if (invadorsArr[i].isOnBottomBorder(top)) {
				gameInst.endGame();
				return true;
			}
		}
		return false;
	}
	
	this.hideAll = function() {
	
		visualElement.style.visibility = "hidden";
		
		var i;
		
		for (i=0;i<INVADORS_NUM;i++) {
			invadorsArr[i].hide();
		}
		
		for (i=0;i<INVADORS_WEAPON_NUM;i++) {
			invadorWeapon[i].hide();
		}
	}
	
	this.moveWeapons = function() {
	
		//move the chopperweapon
		for (i=0;i<INVADORS_WEAPON_NUM;i++) {
			invadorWeapon[i].step();
		}
	}
	
	this.isHit = function(weaponTop,weaponLeft) {
	
		for (i=0;i<INVADORS_NUM; i++) {
			if (invadorsArr[i].isHit(weaponTop,weaponLeft,top,left)) {
				invadorsArr[i].explode();
				return (ROW_NUM-(Math.floor(i/COL_NUM)));
			}
		}
		
		return 0;
	}
	
}
//////////////INVADOR//////////////////////////////////
function Invador(index, inType, topOf, leftOf, row, col) {
		
	var isVisible = false;
	var exploding = false;
	var visualElement = document.getElementById("inv_"+row+"_"+col);
	var topOffset = topOf;
	var leftOffset = leftOf;
	var index;
	var mType = inType;
	var binState = 0;//there are to images for each invador param select which one to show
		
	//move the invador one step	
	this.step = function() {
		
		if (this.isAvailable())
			return;
			
		if (!exploding) {
			binState = (binState + 1)%2; //0 or 1
			visualElement.style.backgroundPosition = (0-((mType*2+binState)*INV_WIDTH))+"px 0px";
		}
	}
		
	//position the invader at the start point
	//show the invader
	this.show = function() {
	
		isVisible = true;
		exploding = false;
		visualElement.style.backgroundPosition = (0-((mType*2+binState)*INV_WIDTH))+"px 0px";
		visualElement.style.visibility = "visible";
	}
	
	this.hide = function() {
	
		isVisible = false;
		visualElement.style.visibility = "hidden";
	}
	
	this.isAvailable = function() {
	
		return !isVisible;
	}
	
	this.isOnLeftBorder = function(invLeft) {
		
		if (!isVisible || exploding)
			return false;
		return invBorderLeft >= (invLeft+leftOffset);
	}
	
	this.isOnRightBorder = function(invLeft) {
	
		if (!isVisible || exploding)
			return false;
		return invBorderRight <= (invLeft+leftOffset+INV_WIDTH);
	}
	
	this.isOnBottomBorder = function(invTop) {
	
		if (!isVisible || exploding)
			return false;
		return invBorderBottom <= (invTop+topOffset+INV_HEIGHT);
	}
	
	this.explode = function() {
		
		visualElement.style.backgroundPosition = (0-((ROW_NUM*2)*INV_WIDTH))+"px 0px";
		setTimeout("invadorsArr["+index+"].explodeMore();",200);
		setTimeout("invadorsArr["+index+"].hide();",400);
		exploding = true;
	}
	
	this.explodeMore = function() {
		
		visualElement.style.backgroundPosition = (0-(((ROW_NUM*2)+1)*INV_WIDTH))+"px 0px";
	}
	
	this.isHit = function(weaponTop,weaponLeft, invTop, invLeft) {
			
		if (!isVisible || exploding)
			return false;
			
		var tp = (invTop+topOffset);
		var lf = (invLeft+leftOffset);
		if (weaponTop>tp && weaponTop<(tp+INV_HEIGHT) && weaponLeft>lf && weaponLeft<(lf+INV_WIDTH))
			return true;
			
		return false;
	}
	
	this.dropBomb = function(invTop, invLeft) {
			
		for (var i=0;i<INVADORS_WEAPON_NUM;i++) {
			if (invadorWeapon[i].isAvailable()) {
				invadorWeapon[i].show(invTop+topOffset+INV_HEIGHT,invLeft+leftOffset+Math.floor(INV_WIDTH/2));
				return;
			}
		}
	}
}

//////////////invador WEAPON//////////////////////////////////
function InvadorWeapon() {

	var visualElement = null;
	var isVisible = false;
	var top;
	var left;
		
	visualElement = document.createElement("IMG");
	visualElement.style.width = "2px";
	visualElement.style.height = "6px";
	visualElement.style.position = "absolute";
	visualElement.style.visibility = "hidden";
	visualElement.src = _IG_GetImageUrl(IMAGES_BASE+"shot.gif");
	visualElement.style.zIndex = 50;
	document.body.appendChild(visualElement);
		
	this.step = function() {
		
		if (!isVisible)
			return;
			
		if (top < topLeftCorner.top+227) {
			top = top+4;
			visualElement.style.top = top + "px";
		}
		else {
			this.hide();
		}
	}
	
	this.hide = function() {
	
		isVisible = false;
		visualElement.style.visibility = "hidden";
	}
	
	this.show = function(topP, leftP) {
			
		isVisible = true;
		top = topP;
		left = leftP;
		visualElement.style.top = top+"px";
		visualElement.style.left = left + "px";
		visualElement.style.visibility = "visible";
				
	}
	
	this.isAvailable = function() {
			
		return !isVisible;
	} 
	
	this.getLeft = function() {
	
		return left;
	}
	
	this.getTop = function() {
	
		return top;
	}
	
}

//////////////SpaceShip//////////////////////////////////
function SpaceShip() {
	
	var visualElement = null;
	var isVisible = false;
	var top;
	var left;
	var direction = 1;
	var binState;
	var exploding = false;
		
	this.create = function() {
			
		top = 10;
		left = topLeftCorner.left;
		
		visualElement = document.getElementById("spaceShipElm");
		visualElement.style.left = left + "px";
		binState = 0;
	}
	
	this.init = function() {
	
		visualElement.style.display = "";
		
		for (i=0;i<MAX_TANK_WEAPON_NUM;i++) {
			tankWeapon[i].hide();
		}
	}
	
	this.isAvailable = function() {
			
		return !isVisible;
	} 
	
	this.show = function() {
			
		isVisible = true;
		exploding = false;
		visualElement.style.top = top+"px";
		visualElement.style.left = left + "px";
		visualElement.style.display = "";
	}
	
	this.hide = function() {
	
		isVisible = false;
		visualElement.style.display = "none";
	}
	
	this.step = function() {
	
		if (!isVisible) {
		
			var rnd = Math.random()*400;
			if (rnd<1) {
				rnd = Math.random()*2;
				if (rnd < 1) {
					left = 5;
					direction = 1;
				}
				else {
					left = WIDTH-25;
					direction = -1;
				}
				this.show();
			}
		} // move the spaceship 
		else {
			if (direction == 1)
				this.moveRight();
			else 
				this.moveLeft();
			if (!exploding) {
				binState = (binState + 1)%2; //0 or 1
				visualElement.style.backgroundPosition = (0-(24*binState))+"px 0px";		
			}
		}
	}
	
	this.explode = function() {
		
		visualElement.style.backgroundPosition = "-48px 0px";
		setTimeout("spaceShip.explodeMore();",200);
		setTimeout("spaceShip.hide();",400);
		exploding = true;
	}
	
	this.explodeMore = function() {
		
		visualElement.style.backgroundPosition = "-72px 0px";
	}
	
	this.isHit = function(weaponTop,weaponLeft) {
	
		if (!isVisible || exploding)
			return false;
		
		weaponTop = weaponTop - topLeftCorner.top;
		weaponLeft = weaponLeft - topLeftCorner.left;
		if (weaponTop>top && weaponTop<top+11 && weaponLeft>left && weaponLeft<left+23)
			return true;
			
		return false;
	}
		
	this.moveLeft = function() {
		
		if (left > 5) {
			left = left-3;
			visualElement.style.left = left + "px";
		}
		else this.hide();
		
	}
	
	this.moveRight = function() {
	
		if (left < WIDTH-25) {
			left = left+3;
			visualElement.style.left = left + "px";
		}
		else this.hide();
		
	}	
}


//////////////TANK WEAPON//////////////////////////////////
function TankWeapon() {

	var visualElement = null;
	var isVisible = false;
	var top;
	var left;
		
	visualElement = document.createElement("IMG");
	visualElement.style.width = "2px";
	visualElement.style.height = "6px";
	visualElement.style.position = "absolute";
	visualElement.style.visibility = "hidden";
	visualElement.src = _IG_GetImageUrl(IMAGES_BASE+"shot.gif");
	visualElement.style.zIndex = 50;
	document.body.appendChild(visualElement);
		
	this.step = function() {
		
		if (!isVisible)
			return;
			
		if (top > topLeftCorner.top+12)
			top = top-8;
		else 
			this.hide();
		
		visualElement.style.top = top + "px";
	}
	
	this.hide = function() {
	
		isVisible = false;
		visualElement.style.visibility = "hidden";
	}
	
	this.show = function(topP, leftP) {
			
		isVisible = true;
		top = topP;
		left = leftP;
		visualElement.style.top = top+"px";
		visualElement.style.left = left + "px";
		visualElement.style.visibility = "visible";
		playSound('shoot');
				
	}
	
	this.isAvailable = function() {
			
		return !isVisible;
	} 
	
	this.getLeft = function() {
	
		return left;
	}
	
	this.getTop = function() {
	
		return top;
	}
}


//////////////TANK//////////////////////////////////
function Tank() {
	
	var visualElement = null;
	var top;
	var left;
	var exploding = false;
	var invulnerable=false;
	
	this.create = function() {

		left = 118;
		top = topLeftCorner.top+220;//at topLeftCorner.top+210 invaders kill you, in order to be able to shoot them till the end the shot must start lower.
		
		visualElement = document.getElementById("tankElm");
		visualElement.style.left = left + "px";
		
		for (i=0;i<MAX_TANK_WEAPON_NUM;i++) {
			tankWeapon[i] = new TankWeapon();
		}		
	}
	
	this.init = function() {
		invulnerable=false;	
		exploding = false;
		visualElement.style.visibility = "visible";
		
		for (i=0;i<MAX_TANK_WEAPON_NUM;i++) {
			tankWeapon[i].hide();
		}
	}
	
	this.show = function() {
	
		exploding = false;
		visualElement.src = _IG_GetImageUrl(IMAGES_BASE+"user_ship.gif");
	}
	
	this.moveWeapons = function() {
	
		//move the tankweapon
		for (i=0;i<MAX_TANK_WEAPON_NUM;i++) {
			tankWeapon[i].step();
		}
	}
	
	this.isHit = function(weaponTop,weaponLeft) {
		if (exploding)
		{
			return false;
		}
		if (invulnerable)
			return false;
		weaponLeft = weaponLeft - topLeftCorner.left;
		if (weaponTop>top && weaponTop<top+11 && weaponLeft>left && weaponLeft<left+23)
			return true;
		
		return false;
	}
	
	this.explode = function() {
		invulnerable=true;
		visualElement.src = _IG_GetImageUrl(IMAGES_BASE+"explosion.gif");
		setTimeout("tank.show();",1000);
		setTimeout("tank.allowHit();",1300);
		exploding = true;
	}
	this.allowHit = function(){
		invulnerable=false;
	}
	this.moveLeft = function() {
		
		if (exploding)
			return;
		
		if (left > 5)
			left = left-3;
		
		visualElement.style.left = left + "px";
		
	}
	
	this.moveRight = function() {
	
		if (exploding)
			return;
		if (left < WIDTH-25)
			left = left+3;
		
		visualElement.style.left = left + "px";
	}
		
	this.shoot = function() {
	
		if (exploding)
			return;
			
		for (var i=0;i<tankWeaponNum;i++) {
			if (tankWeapon[i].isAvailable()) {
				tankWeapon[i].show(top,topLeftCorner.left+left+11);
				return;
			}
		}
	}
}

var tank;
var invadorsBlock;
var spaceShip;
function GameControler() {
	
	var score = 0;
	var live = 3;
	
	var isStarted = false;
	var isPaused = true;
	var intervalHandle = 0;
	var multiShotHandle = 0;
	var directionIntervalHandler = 0;
	var bonusTimerHandler = 0;
	
	this.init = function() {
		
		isStarted = false;
		isPaused = true;
		
		var i;
		var row,col;
		//init game varibles
		
		topLeftCorner = this.getObjectPos(document.getElementById("anchorBrdPos"));
		scoreEl = document.getElementById("scoreElm");
		levelEl = document.getElementById("levelElm");
		liveEl = document.getElementById("liveElm");
		pauseBtnEl = document.getElementById("pauseBtnElm");
		endGameEl = document.getElementById("gameOver");
		
		
		tank = new Tank();
		tank.create();
		
		invadorsBlock = new Invadors();
		invadorsBlock.create();
		
		spaceShip = new SpaceShip();
		spaceShip.create();
	}
	
	this.newGame = function() {
		trackEvent("New Game");
		//init the statistics params
		score = 0;
		gameLevel = 1;
		live = 3;
		speed = 10;
		speedCounter = 0;
		isStarted = true;
		isPaused = false;
		document.getElementById("openScreenImg").style.visibility = "hidden";
		this.setPauseState();
		this.updateStatistics();		
		
		//init the positions
		topLeftCorner = this.getObjectPos(document.getElementById("anchorBrdPos"));
		invBorderRight = topLeftCorner.left+WIDTH-10;
		invBorderLeft = topLeftCorner.left+10;
		invBorderBottom = topLeftCorner.top+210;

		//hide game over and spaceship
		endGameEl.style.display = "none";
		endGameEl.style.top = "-700px";
		spaceShip.hide();
		
		tank.init();
		invadorsBlock.init();
		
		//start the timer
		clearInterval(intervalHandle);
		intervalHandle = setInterval('gameInst.step()',50);			
	}
	
	//move the elements 
	this.step = function() {
				
		if (!isStarted || isPaused)
			return;
		
		var speedFactor = speed-gameLevel-Math.floor(invRowsDown/3);
		if (speedFactor<3)
			speedFactor = 3;
		speedCounter = (speedCounter + 1) % (speedFactor);
		if (speedCounter == 0) {
			invadorsBlock.step();
		}
		this.moveWeapons();
	}
	
	this.moveWeapons = function() {
	
		tank.moveWeapons();
		invadorsBlock.moveWeapons();
		spaceShip.step();
		
		this.checkCollisions();
		this.updateStatistics();
	}
	
	this.updateStatistics = function() {
	
		scoreEl.innerHTML = score;
		levelEl.innerHTML = gameLevel;
		liveEl.innerHTML = live;
		
	}
	
	this.checkCollisions = function() {
	
		var i,j;
		var tmpPoint = 0;
		
		//check collisions
		for (j=0;j<MAX_TANK_WEAPON_NUM;j++) {
			if (!tankWeapon[j].isAvailable()) {
				tmpPoint = invadorsBlock.isHit(tankWeapon[j].getTop(),tankWeapon[j].getLeft());
				if (tmpPoint != 0) {
					tankWeapon[j].hide();
					score = score + tmpPoint;
					playSound('hit');
				}
				
				if(spaceShip.isHit(tankWeapon[j].getTop(),tankWeapon[j].getLeft())) {
					spaceShip.explode();
					tankWeaponNum = 2;
					clearTimeout(multiShotHandle);
					multiShotHandle = setTimeout("tankWeaponNum=1;",25000);
					tankWeapon[j].hide();
					score = score + 50;
					playSound('death1');
				}
			}			
		}
		
		//check collisions
		for (j=0;j<INVADORS_WEAPON_NUM;j++) {
			if (!invadorWeapon[j].isAvailable()) {
				if (tank.isHit(invadorWeapon[j].getTop(),invadorWeapon[j].getLeft())) {
					tank.explode();
					playSound('death1');
					this.decreaseLive();					
				}
			}
		}
	}
	
	this.nextLevel = function() {
		
		gameLevel++;
		if (gameLevel%2==0)
			live++;
		speed--;
		if (speed < 1) speed = 1; 
		invadorsBlock.init();
	}
	
	this.decreaseLive = function() {
		live--;
		if (live==0)
			this.endGame();
	}
	
	this.endGame = function() {
		trackEvent("Game Over");
		isStarted = false;
		isPaused = true;
		invadorsBlock.hideAll()
		spaceShip.hide();
		endGameEl.style.display = "";
		endGameEl.style.top = topLeftCorner.top+30+"px";
		endGameEl.style.left = topLeftCorner.left+25+"px";
	}
	
	this.setPauseState = function() {
	
		if (isPaused) {
			pauseBtnEl.style.background = "transparent url("+_IG_GetImageUrl(IMAGES_BASE+'soundoff_play.png')+") -16px 0px no-repeat";
		} else {
			pauseBtnEl.style.background = "transparent";
		}
	}
	
	//puase or continue the game
	this.pauseClicked = function() {
	
		if (!isStarted) {
			this.newGame();
			return;
		}
			
		if (isPaused) {
			
			clearInterval(intervalHandle);
			intervalHandle = setInterval('gameInst.step()',50);
			isPaused = false;
			this.setPauseState();
			
		}
		else {
			clearInterval(intervalHandle);
			isPaused = true;
			this.setPauseState();
		}
	}
	
	this.reportTopScore = function() {
	
		lp_reportScore(score);
	}		
		
	this.keyPressed = function(e) {
		try {
			if (lp_isPopupMenuOpen()) return true;
		}catch (ee) {}
		
		if (!isStarted || isPaused)
			return;
		
		var keynum = getKey(e);
		switch (keynum) {
			
			case 37: 
			case 52: 
			case 65460:
				tank.moveLeft();
				clearInterval(directionIntervalHandler);
				directionIntervalHandler = setInterval("tank.moveLeft();",50);
				e.keycode=0;
				return false;
			case 39:
			case 54:
			case 65462:
				tank.moveRight();
				clearInterval(directionIntervalHandler);
				directionIntervalHandler = setInterval("tank.moveRight();",50);
				e.keycode=0;
				return false;
			case 32:
			case 13:
			case 53:
			case 65461:
			case 38:
			case 56:
			case 65464:
				tank.shoot();
				e.keycode=0;
				return false;
		}
		return true;
	}
	this.keyDiscard = function(e) {//this function discards keypress, which is a surplus event
		try {
			if (lp_isPopupMenuOpen()) return true;
		}catch (ee) {}
		
		if (!isStarted || isPaused)
			return;
		
		var keynum = getKey(e);
		switch (keynum) {
			case 0:
			case 37: 
			case 52: 
			case 65460:
			case 39:
			case 54:
			case 65462:
			case 32:
			case 13:
			case 53:
			case 65461:
			case 38:
			case 56:
			case 65464:
				return false;
		}
		return true;
	}
	this.keyReleased = function(e) {
		try {
			if (lp_isPopupMenuOpen()) return true;
		}catch (ee) {}
		
		var keynum = getKey(e);
		switch (keynum) {
			
			case 37: 
			case 52: 
			case 65460:
			case 39:
			case 54:
			case 65462:
				clearInterval(directionIntervalHandler);
				return false;
		}
		return true;
	}
	
	this.getObjectPos = function(a){
		var b={},c=a;
		b.left=c.offsetLeft;
		b.top=c.offsetTop;
		while(c.offsetParent!=null){
			var d=c.offsetParent;
			b.left+=d.offsetLeft;
			b.top+=d.offsetTop;
			c=d;
		}
		return b
	}
}

function getKey(e) {
	
	if(window.event) {
		return window.event.keyCode;
	}
	if(e.which) {
		return e.which;
	}	
	return 0;
}

var mute = false;
function playSound(sid) {
	if (!mute)
		soundManager.play(sid);
}

function toggleSound() {
	
	mute = !mute;
	if (mute)
		document.getElementById("sndControlr").style.background = "transparent url("+_IG_GetImageUrl(IMAGES_BASE+'soundoff_play.png')+") 0px 0px no-repeat";
	else
		document.getElementById("sndControlr").style.background = "transparent";
}

function close_ad(){
		
}
	
</script>
			
	<center>
	<div style='height:20px;font-size:1px;'></div>
	<table width="260" height="253" cellspacing="0" border="0" cellpadding="0">
		<tr>
			<td id="anchorBrdPos" width="260" height="237" colspan="2">
				<table width="260" height="237" border="0" cellpadding="0" cellspacing="0" id="tableBG">
					<tr>
						<td valign="bottom" height="20" colspan="8">
							<div id="spaceShipElm" style="width:24px; height:11px;display:none; position:relative;" ></div> 
						</td>
					</tr>
					<tr>
						<td height="200" colspan="8" align="center"><img id="openScreenImg" width="205" height="199" onClick="close_ad(); gameInst.newGame();" /></td>
					</tr>
					<tr>
						<td valign="top" height="17" colspan="8">
							<img id="tankElm" width="23" height="11" style="position:relative;" />
						</td>
					</tr>
				</table>
			</td>
		</tr>
		<tr>
			<td width="260" height="16" colspan="2">
				<table width="260" height="16" border="0" cellpadding="0" cellspacing="0" id="bottomTable">
					<tr>
						<td height="16" width="32" onClick="close_ad(); gameInst.newGame();" style="cursor:pointer;"></td>
						<td height="16" width="16" id="sndControlr" onClick="toggleSound();" style="cursor:pointer;"></td>
						<td height="16" width="16" id="pauseBtnElm" onClick="close_ad(); gameInst.pauseClicked();" style="cursor:pointer; "></td>
						<td height="16" width="54"></td>
						<td height="16" width="40" id="scoreElm" class="statisticsItems">0</td>
						<td height="16" width="40"></td>
						<td height="16" width="16" id="levelElm" class="statisticsItems">1</td>
						<td height="16" width="34"></td>
						<td height="16" width="12" id="liveElm" class="statisticsItems">3</td>
					</tr>
				</table>
			</td>
		</tr>
	</table>
	<div style="width:248px;height:14px;margin-top:5px;">
		<script type="text/javascript">
			GA_googleFillSlot("invaders_txt");
		</script>
	</div>
	</center>
	
	<table id="invadorsTbl" cellpadding="0" cellspacing="5" border="0" width="181" height="80" style="z-index:50; position:absolute; visibility:hidden;">
	<script type="text/javascript">
		var row,col;
		for (row=0;row<ROW_NUM; row++) {
			document.write("<tr>");
			for (col=0;col<COL_NUM; col++) {
				document.write("<td id='inv_"+row+"_"+col+"' class='invadorEXstyle'></td>");
			}
			document.write("</tr>");
		}
	</script>
	</table>
							
	<table id="gameOver" width="208" height="120" border="0" cellpadding="0" cellspacing="0" style="position:absolute;display:none; z-index:90;">
	<tr>
		<td height="28"><img id="overImg" width="208" height="28" /></td>
	</tr>
	<tr>
		<td height="40"></td>
	</tr>
	<tr>
		<td valign="top" align="center" class="gameOverItems" style="color:#b6c812;" onClick=";gameInst.newGame();">__MSG_new__</td>
	</tr>
	<tr>
		<td valign="top" align="center"><a class="gameOverItems" style="color:#ed931d;" target="_blank" onclick="trackEvent('Went to get more games');" href="http://www.labpixies.com/gadgets/?category=1">__MSG_more__</a></td>
	</tr> 
	</table>
	<!-- google analytics -->	
  <script type="text/javascript"> _IG_Analytics("UA-345375-1","/invaders_v1"); </script>
  <iframe width="1" height="1" style="width:1px; height:1px; overflow:hidden; position:absolute; visibility:hidden;" src="http://static.labpixies.com/campaigns/invaders/analytics.html"></iframe>
	<!-- LP footer -->
  <div>
  	<script type="text/javascript">
      var mMENU = _IG_GetCachedUrl("http://cdn.labpixies.com/infra/js/lp_footer.js");
      document.write('<scr'+'ipt type="text/javascript" src="'+mMENU+'"></scr'+'ipt>');
    </script>
  </div>
  		
<!-- init module -->
<script type="text/javascript" >
	
	
	var pageTracker = _gat._getTracker("UA-345375-1");
	pageTracker._initData();
	
	function trackEvent(eventName)
	{
		try {
      pageTracker._trackEvent('inavders',eventName);
    } catch (ee) {}
	}
	
	function init_soundmanager()
	{
		var SER = 'http://cdn.labpixies.com/';
		soundManager.waitForWindowLoad = true;	
		soundManager.url = _IG_GetCachedUrl(SER + 'infra/flash/soundmanager2.swf'); // override default SWF url
		soundManager.debugMode=false;
		soundManager.consoleOnly = false;
		
		soundManager.onload = function() {
			// soundManager is initialised, ready to use. Create a sound for this demo page.					
		
			soundManager.createSound('shoot',SER +'campaigns/invaders/audio/1.mp3');
			soundManager.createSound('hit',SER +'campaigns/invaders/audio/2.mp3');
			soundManager.createSound('death1',SER +'campaigns/invaders/audio/3.mp3');
		}
	}
	
	_IG_RegisterOnloadHandler(function() {
		
		gameInst = new GameControler();
		gameInst.init();
		
		$lp(document).keydown(function(e){return gameInst.keyPressed(e);});
		$lp(document).keypress(function(e){return gameInst.keyDiscard(e);});
		$lp(document).keyup(function(e){return gameInst.keyReleased(e);});
		
		$lp(function()
		{
			$lp('.invadorEXstyle').css('background','url('+_IG_GetImageUrl(IMAGES_BASE+"/all.gif")+') 0px 0px no-repeat');
			$lp('#tableBG').css('background','url('+_IG_GetImageUrl(IMAGES_BASE+"background.jpg")+')');
			$lp('#spaceShipElm').css('background','transparent url('+_IG_GetImageUrl(IMAGES_BASE+"bothships.gif")+') -24px 0px no-repeat');
			$lp('#openScreenImg').attr('src',_IG_GetImageUrl(IMAGES_BASE+'open_screen.png'));
			$lp('#tankElm').attr('src',_IG_GetImageUrl(IMAGES_BASE+"user_ship.gif"));
			$lp('#bottomTable').css('background','url('+_IG_GetImageUrl(IMAGES_BASE+"bottom.png")+')');
			$lp('#pauseBtnElm').css('background','transparent url('+_IG_GetImageUrl(IMAGES_BASE+"soundoff_play.png")+') -16px 0px no-repeat');
			$lp('#overImg').attr('src',_IG_GetImageUrl(IMAGES_BASE+'gameover.gif'));
			
		});
		
		init_soundmanager();
	});
</script>

<script type="text/javascript">
	var mTOPS=_IG_GetCachedUrl("http://cdn.labpixies.com/top_score/lp_top_score.js");
	document.write('<scr'+'ipt type="text/javascript" src="'+mTOPS+'"></scr'+'ipt>');
</script>
		]]>
</Content>
</Module>