var BackgroundSwf = Class.create(SwfInstance, {
  title: '',
  background: '',
  waitToShowTitle: false,
  callbackFunction: null,

  initialize: function($super, url, targetId, width, height, minVersion, flashVars, params, attrs, options) {
    this.title = flashVars['title'];
    this.background = flashVars['background'];
    this.images = flashVars['images'];
    this.height = height;
    attrs = Object.extend({allowfullscreen: 'true'}, attrs);
    $super(url, targetId, width, height, minVersion, flashVars, params, attrs, options);
  },

  setupObservers: function($super) {
    Event.observe(this.swf, 'flash:onBackgroundShown', function() {
      this.swf.setStyle({height: 586 + 'px'});
      if (!this.waitToShowTitle) this.showTitle();
      this.showProduct(this.images[0], this.images[1]);
      this.images = false;
      if (this.callbackFunction) this.callbackFunction();
    }.bindAsEventListener(this));
    $super();
  },

  onBuilt: function() {
    this.loadSection(this.title, this.background, false, false);
  },

  loadSection: function(title, background, transition, waitToShowTitle, callbackFunction) {
    this.title = title;
    this.swf.loadSection(title, background, transition);
    this.waitToShowTitle = waitToShowTitle;
    this.callbackFunction = callbackFunction;
  },

  showTitle: function() {
    if (this.title) this.swf.showTitle();
  },

  showProduct: function(images, thumbs) {
    if (images && images.length) {
      this.swf.showProduct(images, thumbs);
    }
  }
});