function cTileController()
{
	this.tiles = [];
	
	// tile0
	var tile0 = new cTile();
	tile0.walkable = true;
	tile0.frame = 1;
	tile0.draw = function( x, y, domParent )
	{
		var tile = document.createElement( "div" );
		tile.style.position = "absolute";
		tile.style.width = g_tileW + "px";
		tile.style.height = g_tileH + "px";
		tile.style.left = x * g_tileW + "px";
		tile.style.top = y * g_tileH + "px";
		//tile.style.border = "1px solid #ddd";
		tile.style.backgroundColor = "#808080";
		domParent.appendChild( tile );
	}
	this.tiles.push( tile0 ); 

	var tile1 = new cTile();
	tile1.walkable = false;
	tile1.frame = 2;
	tile1.draw = function( x, y, domParent )
	{
		var tile = document.createElement( "div" );
		tile.style.position = "absolute";
		tile.style.width = g_tileW + "px";//this.tileW;
		tile.style.height = g_tileH + "px";//this.tileH;
		tile.style.left = x * g_tileW + "px";
		tile.style.top = y * g_tileH + "px";
		//tile.style.border = "1px solid #000";
		tile.style.backgroundImage= "url(images/tiles.png)"
		tile.style.backgroundPosition = "-40px 0px"
		domParent.appendChild( tile );
	}		
	this.tiles.push( tile1 );
	
	// Dooors
	var door1 = new cDoor(1, 1, 6);
	var door2 = new cDoor(0, 14, 6);
	
	
	this.tiles.push( door1 );
	this.tiles.push( door2 );
	
	// Clouds
	var cloud1 = new cCloud();
	cloud1.frame = 4;
	this.tiles.push( cloud1 );
	
	// Dooors
	var door3 = new cDoor(1, 14, 4);
	var door4 = new cDoor(0, 1, 4);
	this.tiles.push( door3 );
	this.tiles.push( door4 );
	
	// Moving tles
	var move1 = new cMovingTile1();
	this.tiles.push( move1 );
	
		var tile1 = new cTile();
	tile1.walkable = false;
	tile1.frame = 2;
	tile1.draw = function( x, y, domParent )
	{
		var tile = document.createElement( "div" );
		tile.style.position = "absolute";
		tile.style.width = g_tileW + "px";//this.tileW;
		tile.style.height = g_tileH + "px";//this.tileH;
		tile.style.left = x * g_tileW + "px";
		tile.style.top = y * g_tileH + "px";
		//tile.style.border = "1px solid #000";
		tile.style.backgroundImage= "url(images/tiles.png)"
		tile.style.backgroundPosition = "-20px 0px"
		domParent.appendChild( tile );
	}		
	this.tiles.push( tile1 );	
	
	this.tiles.push( new cDoor( 1, 14, 12 ) );
	this.tiles.push( new cDoor( 0, 1, 12 ) );
}

function cTile()
{
	this.walkable;
	this.frame;
	this.draw = function( x, y, domParent )
	{
		// Overrideable
	}
};

function cDoor( p_newMap, p_newCharX, p_newCharY )
{
	// This should really inherit from cTile
	this.walkable = true;
	this.frame = 3;
	this.draw = function( x, y, domParent )
	{
		var tile = document.createElement( "div" );
		tile.style.position = "absolute";
		tile.style.width = g_tileW + "px";
		tile.style.height = g_tileH + "px";
		tile.style.left = x * g_tileW + "px";
		tile.style.top = y * g_tileH + "px";
		//tile.style.border = "1px solid #252";

		tile.style.backgroundImage= "url(images/tiles.png)"
		tile.style.backgroundPosition = "-80px 0px"
		domParent.appendChild( tile );
	}
	
	this.door = true;
	this.newMap = p_newMap;
	this.newCharX = p_newCharX;
	this.newCharY = p_newCharY;
}

function cCloud()
{
	// This should really inherit from cTile
	this.walkable = true;
	this.cloud = true;
	this.frame = 4;
	this.draw = function( x, y, domParent )
	{
		// Overrideable
		var tile = document.createElement( "div" );
		tile.style.position = "absolute";
		tile.style.width = g_tileW + "px";
		tile.style.height = g_tileH + "px";
		tile.style.left = x * g_tileW + "px";
		tile.style.top = y * g_tileH + "px";
		//tile.style.border = "1px solid #252";
		tile.style.backgroundImage= "url(images/tiles.png)"
		tile.style.backgroundPosition = "-60px 0px"
		domParent.appendChild( tile );
	}
};

cMovingTile1.prototype = new cTile(); 
cMovingTile1.prototype.constructor = cMovingTile1;
function cMovingTile1( p_id )
{
	this.speed = 2;
	this.dirx = 0;
	this.diry = 1;
	this.minY = 0;
	this.maxY = 2;
	this.walkable = true;
	
	this.width = g_tileW / 2;
	this.height = g_tileH / 2;
	this.id = p_id;
	
	this.draw = function( x, y, domParent )
	{
		this.xTile = x * g_tileW;
		this.yTile = y * g_tileH;
		this.x = x;
		this.y = y;
		
		// Overrideable
		var tile = document.createElement( "div" );
		tile.style.position = "absolute";
		tile.style.width = g_tileW + "px";
		tile.style.height = g_tileH + "px";
		tile.style.left = x * g_tileW + "px";
		tile.style.top = y * g_tileH + "px";
		//tile.style.border = "1px solid #252";
		tile.style.backgroundColor = "#ddd";
		domParent.appendChild( tile );
	}
	
}

