/**
@author bibby
Block, Wall, and Pushable classes.
Walls and Pushables are Blocks with unique colors and a moveable boolean,
Blocks have dimensions and position, and a methods to show it
**/

var Block = function(){};
Block.prototype = new Element();
Block.prototype.extend(
{
	id:null,
	dim:[24,24],
	moveable:null,
	color:'black',
	img:null,
	
	makeimg: function()
	{
		if(is(this.id,'null'))
		{
			this.id='block_'+(Math.floor(Math.random()*78000));
		};
		
		elm = document.createElement('DIV');
		with(elm.style)
		{
			position='absolute';
			backgroundColor=this.color;
		}
		elm.id = this.id;
		this.img= elm;
		return this;
	},
	
	display:function()
	{
		if(!is(document.getElementById(this.id)))
		{
			with(this.img.style)
			{
				top = this.pos.top;
				left = this.pos.left;
				width = this.dim[0];
				height = this.dim[1];
			}
			
			document.body.appendChild(this.img);
		};
	},
	
	load:function(){
		this.makeimg().display();
		if(is(Contact,'object'))
			Contact.register(this,'Block');
	}
});


var Wall = function(){};
Wall.prototype = new Block();
Wall.prototype.extend({
	moveable:false,
	color:'gray'
});


var Pushable = function(){};
Pushable.prototype = new Block();
Pushable.prototype.extend({
	moveable:true,
	color:'#abcdef',
	move:function(property,moveby,movedata)
	{
		var area = this.area(property,this.pos[property]+moveby);
		if(!Contact.mayMove(area,this.id,[property,moveby]))
		{
			return false;
		}
		
		this.pos[property]+=moveby;
		this.img.style[property] = this.pos[property]+'px';
		Contact.update(this);
		return true;
	}
});
