function cEnemyController()
{
	this.currentEnemies = null;
		
	// Enemy brain
	this.setMapEnemies = function( mapNumber )
	{
		var tmpEnemies = [];
		
		var enemyArray = g_enemies[ mapNumber ];
		
		for ( var i = 0; i < enemyArray.length; i++ )
		{
			switch( enemyArray[ i ][ 0 ] )
			{
				case 0:
					break;
				case 1:
					var tmpEnemy = new cEnemy1(tmpEnemies.length.toString());
					tmpEnemy.xTile = enemyArray[ i ][ 1 ];
					tmpEnemy.yTile = enemyArray[ i ][ 2 ];
					tmpEnemy.y = ( ( tmpEnemy.yTile + 1 ) * g_tileH ) - tmpEnemy.centre_height;
					tmpEnemy.x = tmpEnemy.xTile * g_tileW + tmpEnemy.centre_width;
					tmpEnemies.push( tmpEnemy );
				case 2:
					break;
			}
		}

		this.currentEnemies = tmpEnemies;

	}
	
	this.drawEnemies = function( domParent )
	{
		for (var i = 0; i < this.currentEnemies.length; ++i )
		{
			this.currentEnemies[ i ].draw( domParent );
		}	
	}

	this.update = function()
	{
		// Check if enemies
		for ( var i = 0; i < this.currentEnemies.length; i++ )
		{
			this.currentEnemies[ i ].update();
		}
	}
}


cEnemy.prototype = new cChar(); 
cEnemy.prototype.constructor = cEnemy;
function cEnemy( p_Id )
{
	this.type;
	this.id = p_Id;
	this.points;
	this.xMove;
	this.yMove;
	
	this.erase = function( domParent )
	{
		var item = document.getElementById( "enemy" + this.id );
		if ( item )
			item.parentNode.removeChild( item );
	}
}

cEnemy1.prototype = new cEnemy(); 
cEnemy1.prototype.constructor = cEnemy1;
function cEnemy1( p_Id )
{
	this.type = 1;
	this.id = p_Id;
	
	this.constructor = function()
	{
		this.xMove = 1;
		this.yMove = 0;
		this.speed = 4;
		this.width = 15;
		this.height = 15;
		this.centre_height = this.height / 2;
		this.centre_width = this.width / 2;
		
		this.animFrame = 0;
		
	};
	
	this.draw = function( domParent )
	{
		var tile = document.createElement( "div" );
		tile.style.position = "absolute";
		tile.setAttribute( "id", "enemy" + this.id );
		tile.style.width = this.width + "px";
		tile.style.height = this.height + "px";
		
		tile.style.left = this.x - this.centre_width + "px";
		tile.style.top = this.y - this.centre_height + "px";
		
		tile.style.backgroundImage = "url(images/characters.png)";
		tile.style.backgroundPosition = "0px -15px";
		
		this.domRef = tile;
		domParent.appendChild( tile );
	}
	
	this.update = function()
	{
		this.getMyCorners( this.x + this.speed * this.xMove, ( this.y + 1 ) + this.speed * this.yMove);
		if ( ! this.downleft && ! this.downright )
		{
		    this.moveChar( this.xMove, this.yMove);
		}
		else
		{
	    	this.xMove = -this.xMove;
	    	this.yMove = -this.yMove;
		}
		var xdist = this.x - game.player.x;
	 	var ydist = this.y - game.player.y;

		if ( Math.sqrt( xdist * xdist + ydist * ydist ) < this.centre_width + game.player.centre_width)
		{
		 	game.player.hit();
  		}
		
		this.domRef.style.backgroundPosition = "-" + (this.animFrame++ % 2 * this.width ) + "px -15px";
	}
	this.constructor();
}


