var SPECS = SPECS=='object'?SPECS:{};

function toRad(x){
	return (x*Math.PI)/180;
}
SPECS.ROOT = function(id){
	thisObj = this;
	this._canvas = $(id).get();
	this._context = this._canvas.getContext('2d');
	
	var specsianer_mc = new SPECS.MOVIECLIP();
	
	var specinator_mc = new SPECS.IMAGE();
	var fn = function(obj){
		obj.x(-obj.width()/2);
		obj.y(-obj.height());
		obj.rotate(20);
		specsianer_mc.add(obj.get(), 0, 0, obj.width(), obj.height());
		
		thisObj.add(specsianer_mc.get(), 0, 0, obj.width(), obj.height());		
	}
	specinator_mc.loadUrl('co/asset/pic/specsianer.png', fn);
	
	
	
	
}
SPECS.ROOT.prototype={
	add:function(obj, x, y, width, height){
		this._canvas.width = Math.max(x+width, this.width());
		this._canvas.height = Math.max(x+height, this.height());
		this._context.save();
		this._context.drawImage(obj, 0, 0, width, height);
		this._context.restore();
	},
	height:function(){
		return this._canvas.height;
	},
	width:function(){
		return this._canvas.width;
	},
	rotate:function(deg){
		alert(toRad(deg));
		this._context.rotate(toRad(deg));
	}
}

SPECS.MOVIECLIP = function(){
	this._canvas = $('canvas').get();
	this._context = this._canvas.getContext('2d');
}
SPECS.MOVIECLIP.prototype = {
	get:function(){
		return this._canvas;
	},
	add:function(obj, x, y, width, height){
		
		this._canvas.width = width;
		this._canvas.height = height;
		this._context.save();
		
		this._context.drawImage(obj, 0, 0, width, height);
		this._context.restore();
	},
	x:function(x){
		this._context.translate(x, 0);
	},
	y:function(y){
		this._context.translate(0, y);
	},
	height:function(){
		return this._canvas.height;
	},
	width:function(){
		return this._canvas.width;
	},
	rotate:function(deg){
		this._context.rotate(toRad(deg));
	}, 
	draw:function(){
		
	}
}
SPECS.IMAGE = function(){
	this.image = new Image();
	
}
SPECS.IMAGE.prototype = {
	get:function(){
		return this.image;
	},
	loadUrl:function(url, fn){
		this.image.onload = function(){
			var  container = new SPECS.MOVIECLIP();
			container.add(this, 0, 0, this.width, this.height);
			fn(container);
		}
		this.image.src = url;
	}
}
