FlashBuffer = function() {
  this.buffer = [];
  this.apply_immediately = false;
}

FlashBuffer._instance = null;
FlashBuffer.instance = function() {
  if(!FlashBuffer._instance)
    FlashBuffer._instance = new FlashBuffer();
    
  return FlashBuffer._instance;
}

FlashBuffer.prototype = {
  add: function() {
    this.buffer.push(arguments);
    
    if(this.apply_immediately)
      this.apply();
  },
  
  apply: function() {
    this.apply_immediately = true;
    for(var i = 0; i < this.buffer.length; i ++) {
      swfobject.embedSWF.apply(window, this.buffer[i]);
    }
    this.buffer = [];
  }
}
