function cItemController()
{

	this.getMapItems = function( mapNumber )
	{
		var tmpItems = [];
		
		var itemArray = g_items[ mapNumber ];
		
		for ( var i = 0; i < itemArray.length; i++ )
		{
			switch( itemArray[ i ][ 0 ] )
			{
				case 0:
					break;
				case 1:
					var tmpItem = new cItem1(tmpItems.length.toString());
					tmpItem.x = itemArray[ i ][ 1 ];
					tmpItem.y = itemArray[ i ][ 2 ];
					tmpItems.push( tmpItem );
					break;
				case 2:
					var tmpItem = new cItem2(tmpItems.length.toString());
					tmpItem.x = itemArray[ i ][ 1 ];
					tmpItem.y = itemArray[ i ][ 2 ];
					tmpItems.push( tmpItem );
					break;
				case 3:
					var tmpItem = new cItem_Key(tmpItems.length.toString());
					tmpItem.x = itemArray[ i ][ 1 ];
					tmpItem.y = itemArray[ i ][ 2 ];
					tmpItems.push( tmpItem );
					break;
			}
		}

		return tmpItems;
	}
	
	this.setMapItems = function( mapNumber, itemsArray )
	{
	
	}
}


function cItem()
{
	this.type;
	this.points;
	this.x;
	this.y;
	this.width;
	this.height;
	this.draw = function( domParent )
	{
	
	}
	this.got = function()
	{
		// When the item is collected
	}
}


cItem1.prototype = new cItem(); 
cItem1.prototype.constructor = cItem1;
function cItem1( p_Id )
{
	this.id = p_Id;
	
	this.constructor = function()
	{
		this.type = 1;	
		this.width = 10;
		this.height = 10;
	};
	
	this.draw = function( domParent )
	{
		var tile = document.createElement( "div" );
		tile.style.position = "absolute";
		tile.setAttribute( "id", "item" + this.id );
		tile.style.width = this.width + "px";//this.tileW;
		tile.style.height = this.height + "px";//this.tileH;
		tile.style.left = this.x * g_tileW + ( this.width / 2 ) + "px";
		tile.style.top = this.y * g_tileH + ( this.height / 2 ) + "px";
		tile.style.backgroundImage= "url(images/tiles.png)"
		tile.style.backgroundPosition = "0px -20px"
		domParent.appendChild( tile );
	}
	this.erase = function( domParent )
	{
		var item = document.getElementById( "item" + this.id );
		if ( item )
			item.parentNode.removeChild( item );
	}
	this.constructor();
}


cItem2.prototype = new cItem(); 
cItem2.prototype.constructor = cItem2;
function cItem2( p_Id )
{
	this.id = p_Id;
	
	this.constructor = function()
	{
		this.type = 2;	
		this.width = 10;
		this.height = 10;
	};
	
	this.draw = function( domParent )
	{
		var tile = document.createElement( "div" );
		tile.style.position = "absolute";
		tile.setAttribute( "id", "item" + this.id );
		tile.style.width = this.width + "px";
		tile.style.height = this.height + "px";
		tile.style.left = this.x * g_tileW + ( this.width / 2 ) + "px";
		tile.style.top = this.y * g_tileH + ( this.height / 2 ) + "px";
		tile.style.backgroundColor = "#dd0";
		domParent.appendChild( tile );
	}
	this.erase = function( domParent )
	{
		var item = document.getElementById( "item" + this.id );
		if ( item )
			item.parentNode.removeChild( item );
	}
	this.constructor();
}

cItem_Key.prototype = new cItem(); 
cItem_Key.prototype.constructor = cItem_Key;
function cItem_Key( p_Id )
{
	this.id = p_Id;
	
	this.constructor = function()
	{	
		this.type = 3;
		this.width = 10;
		this.height = 11;
	};
	
	this.draw = function( domParent )
	{
		var tile = document.createElement( "div" );
		tile.style.position = "absolute";
		tile.setAttribute( "id", "item" + this.id );
		tile.style.width = this.width + "px";//this.tileW;
		tile.style.height = this.height + "px";//this.tileH;
		tile.style.left = this.x * g_tileW + ( this.width / 2 ) + "px";
		tile.style.top = this.y * g_tileH + ( this.height / 2 ) + "px";
		tile.style.backgroundImage= "url(images/tiles.png)"
		tile.style.backgroundPosition = "-20px -20px"
		domParent.appendChild( tile );
	}
	this.erase = function( domParent )
	{
		var item = document.getElementById( "item" + this.id );
		if ( item )
			item.parentNode.removeChild( item );
	}	
	this.got = function()
	{
		alert( "got the key" );
	}
	this.constructor();
}

