function cItemController()
{

	this.getMapItems = function( mapNumber )
	{
		var tmpItems = [];
		
		var itemArray = g_items[ mapNumber ];
		
		for ( var i = 0; i < itemArray.length; i++ )
		{
			var currentItem = itemArray[ i ];

			var tmpItem = null;
			switch( currentItem[ 0 ] )
			{
				case 1:
					tmpItem = new cItem1(tmpItems.length.toString());
					break;
				case 2:
					tmpItem = new cItem2(tmpItems.length.toString());
					break;
				case 3:
					tmpItem = new cItem_Key(tmpItems.length.toString());
					break;
				case 4:
					tmpItem = new cItem_LastDoor(tmpItems.length.toString());
					break;
				default:
					break;
			}
			
			if(tmpItem !== null)
			{
				tmpItem.x = currentItem[ 1 ];
				tmpItem.y = currentItem[ 2 ];
				tmpItems.push( tmpItem );
			}
		}

		return tmpItems;
	};
	
	this.setMapItems = function( mapNumber, itemsArray ){
	
	};
}


function cItem(){
	this.type;
	this.points;
	this.x;
	this.y;
	this.width;
	this.height;
	this.id;
	this.domRef;
	this.draw = function( domParent ){
	
	};
	this.got = function(){
		// When the item is collected
	};
	this.erase = function( domParent ){
		var item = document.getElementById( "item" + this.id );
		if ( item ){
			item.parentNode.removeChild( item );
			item.style.position = "static";
			item.style.cssFloat = "left";
			item.style.styleFloat = "left";

			//$('score').appendChild(item);
		}
	};
}

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" );
		this.domRef = tile;
		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";
		tile.style.overflow = "hidden";
		domParent.appendChild( tile );
	};
	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 = 20;
		this.height = 20;
	};
	
	this.draw = function( domParent ){
		var tile = document.createElement( "div" );
		this.domRef = tile;
		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  + "px";
		tile.style.top = this.y * g_tileH  + "px";
		tile.style.backgroundImage= "url(images/tiles.png)";
		tile.style.backgroundPosition = "-140px -20px";
		domParent.appendChild( tile );
	};
	
	this.erase = function( domParent ){
		var item = document.getElementById( "item" + this.id );
		if ( item ){
			item.parentNode.removeChild( item );
			item.style.position = "static";
			item.style.cssFloat = "left";
			item.style.styleFloat = "left";
		}
	};

	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" );
		this.domRef = tile;
		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.got = function(){
		return true;
	};
	
	this.erase = function( domParent ){
		var item = document.getElementById( "item" + this.id );
		if ( item )
		{
			item.parentNode.removeChild( item );
			item.style.position = "static";
			item.style.cssFloat = "left";
			item.style.styleFloat = "left";
			$('score').appendChild(item);
		}
	};
	this.constructor();
}

cItem_LastDoor.prototype = new cItem(); 
cItem_LastDoor.prototype.constructor = cItem_LastDoor;
function cItem_LastDoor( p_Id )
{
	this.id = p_Id;
	
	this.constructor = function(){	
		this.type = 4;
		this.width = 10;
		this.height = 11;
	};
	
	this.draw = function( domParent ){
		var tile = document.createElement( "div" );
		this.domRef = tile;
		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 = "transparent";
		domParent.appendChild( tile );
	};
	
	this.erase = function( domParent ){
		var item = document.getElementById( "item" + this.id );
		if ( item )
		{
			item.parentNode.removeChild( item );
			item.style.position = "static";
			item.style.cssFloat = "left";
			item.style.styleFloat = "left";
			this.domRef = null;
		//	$('score').appendChild(item);
		}
	};
	
	this.got = function(){ return false; };

	this.constructor();
}
