
var stfAnimPlayer={

	canvas: null,
	ctx: null,
	fps: 30, // frames per sec
	frame: 0, // current frame number
	time: 0.0, // current play time in seconds
	debug: false,
	width: 0,
	height: 0,
	shapes: [
	//	{
	//		x: 100, y: 50, w: 17, h: 17,
	//		c: "rgb(200,200,255)", fade: 70.0,
	//		fStart: 1*20, yEnd: 540, spd: 5,
	//		f: mv_tetrisfall
	//	}
	],

	init: function(e,shapes){
		this.canvas=$(e).get(0);
		this.ctx=this.canvas.getContext('2d');
		this.canvas.width=$(e).width();
		this.canvas.height=$(e).height();
		this.time=0.0;
		this.frame=0;
		this.shapes=shapes;
		this.width=this.canvas.width;
		this.height=this.canvas.height;
	},

	circle: function(c,x,y,r){
		this.ctx.beginPath();
		this.ctx.fillStyle=c;
		this.ctx.arc(x, y, r, 0, Math.PI*2, true);
		this.ctx.closePath();
		this.ctx.fill();
	},

	rect: function(c,x,y,w,h) { // colour, x, y, width, height
		this.ctx.fillStyle=c;
		this.ctx.fillRect(x,y,w,h);
	},

	clear: function(){
		this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height);
	},

	start: function(){
		$('.wrapper_inside').css('background','none');
		this.interval=setInterval('stfAnimPlayer.draw()',Math.floor(0.999+1000/this.fps));
	},
	pause: function(){
		clearInterval(this.interval);
	},
	stop: function(){
		clearInterval(this.interval);
		this.frame=0;
		this.time=0.0;
	},
	draw: function(){
		if(this.drawing)
			return true;
		this.drawing=true;
		stillMoving=false;
		sl=this.shapes.length;
		for(var s=0;s<sl;++s){
			var sh=this.shapes[s];
			if(sh.move(this,sh)) stillMoving=true;
		}
		if(!stillMoving)
			this.stop();
		++this.frame;
		this.time=0.0+this.frame/this.fps;
		if(this.debug) $('#debuginfo').html('t='+this.frame+'<br/>sM='+stillMoving+'<br/>');
		this.drawing=false;
	}

};


$(document).ready(function(){
    
		
		var c=document.createElement('canvas');
		c.setAttribute('width',1280);
		c.setAttribute('height',600);
		$(c).css('background-color','#ffffff');
		$('.wrapper').before('<div id="canvaswrapper"></div>');
		var cw=document.getElementById('canvaswrapper');
		cw.appendChild(c);
		if (typeof FlashCanvas != "undefined") 
		{					
			FlashCanvas.initElement(c);
		}
		if(typeof(G_vmlCanvasManager)!='undefined'){
			c=G_vmlCanvasManager.initElement(c);
		}
		stfAnimPlayer.init('canvas',stfAnimShapeList);
		stfAnimPlayer.start();
		
});


