


function animatedObject(args){
	
	var self=this;
	
	this.id=args['id']?args['id']:Math.random()*1000000;
	this.num_of_frames=args['num_of_frames'];
	this.timeout_increment=args['timeout'];
	this.timeout=null;
	this.width=args['width'];
	this.height=args['height'];
	
	this.element=document.getElementById(args['element_id']);
	
	this.current_frame=0;
	
	this.frame_height=this.height/this.num_of_frames;
	
	
	this.animate=function(){
		
		
		var new_y=self.current_frame*self.frame_height;
		self.element.style.backgroundPosition='0px -'+new_y+'px';
		
		//self.element.style.border='2px solid #00f';
			
		self.current_frame++;		
		if(self.current_frame==self.num_of_frames){self.current_frame=0;}
		
		//debug('animate to '+self.element.style.backgroundPosition);
		
		self.timeout=setTimeout(self.animate, self.timeout_increment);
	}
	
}

