var EnterFrame = function( option ){
  this.config( option );
};
EnterFrame.prototype = {

  option:{
    fps:20
  },
  active:true,
  funcs:[],
  tid:null,

  config:function( option ){
    this.seting = $.extend( this.option, option );
    return this;
  },
  start:function(){
    this.active = true;
    this._enterFrame();
    return this;
  },
  _enterFrame:function(){
    if ( this.active ){
      $.each( this.funcs, function( i, f ){ f(); } );
      this.tid = setTimeout(
        $.proxy( this._enterFrame, this ),
        Math.floor( 1000 / this.seting.fps )
      );
    }
  },
  stop:function(){
    this.active = false;
    clearTimeout( this.tid );
    return this;
  },
  add:function( func ){
    this.funcs.push( func );
    return this;
  },
  remove:function( func ){
    this.funcs = $.grep( this.funcs, function( f, i ){
      return ( func !== f );
    } );
    return this;
  }
};

