/**
@author bibby
Base class from which all "physical objects" are derived.
Offers only extensibility and execution of the subclass's load() method
when initialized with paramters [ new Whatever().init(params) ]
**/

var Tangible = function()
{
	this.extend(
	{
		dim:{width:0,height:0},
		id:null,
		moveable:true,
		pos:{left:0,top:0},
		
		init:function(params)
		{
			if(is(params,'object'))
				this.extend(params);
			
			if(is(this.load,'function'))
				this.load();
			
			return this;
		},
		
		/* returns the coordinal area taken up by this object, or the area that the object in motopn would like to be
		@param string optional propery to fake for previewing an area to enter
		@param int optional value to fake
		*/
		area: function(alterProp, alterVal)
		{
			var t,l;
			t = this.pos.top;
			l = this.pos.left;
			if(is(alterProp))
			{
				t = alterProp == 'top' ? alterVal : this.pos.top;
				l = alterProp == 'left' ? alterVal : this.pos.left;
			}
			return {x:[l,(l + this.dim.width)],y:[t,(t + this.dim.height)]};
		},
		
		/**
		data= { property , distance }
		**/
		move:function(data)
		{
			if(!is(data.ok))
				if(!Contact.mayMove( data ))
					return false;
			
			this.pos[data.property]+=data.distance;
			this.img.style[data.property] = this.pos[data.property]+'px';
			Contact.update(this);
			return true;
		}
	});
};
