/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
(function() {
  ff.PackageSelect = function(farbfinder, options)
  {
    this._initialize (farbfinder, options);
  }

  ff.PackageSelect = jQuery.extend(ff.PackageSelect, {
    ANDERE_ABFUELLUNG : 'fl',
    SPRUEHDOSE : 'sd',
    LACKSTIFT : 'ls'
  });

  ff.PackageSelect.prototype = jQuery.extend(ff.PackageSelect.prototype, {
    _initialize: function(farbfinder, options) {
      this._farbfinder = farbfinder;
      this._options = jQuery.extend({
        container : '#container_schritt_5',
        back_button: '#step_5_back_button',
        select_andere_abfuellung: '#andere_abfuellung',
        select_spruehdose: '#spruehdose',
        select_lackstift: '#lackstift',
        headline: '#container_schritt_5_headline',
        default_package : null
      }, options);
      this._id = null;
      this._quality = null;
      this._container = jQuery(this._options.container);
      this._backButton = jQuery(this._options.back_button);
      this._selectAndereAbfuellung = jQuery(this._options.select_andere_abfuellung);
      this._selectSpruehdose = jQuery(this._options.select_spruehdose);
      this._selectLackstift = jQuery(this._options.select_lackstift);

      this._headline = jQuery(this._options.headline);
      this._headlineHtml = this._headline[0].innerHTML;
    },
    startup: function()
    {
      var self = this;
      this._backButton.bind('click keypress', function(ev)
      {
        jQuery(self).trigger('stepBack');
        self.resetHeadline();
      });

      this._selectAndereAbfuellung.bind('click keypress', function(ev)
      {
        jQuery(self).trigger('selectPackage', { 'id': self._id, 'mode' : ff.PackageSelect.ANDERE_ABFUELLUNG });
        self.setHeadline('Abf&uuml;llung: ' + FF_CONFIG.CALLOUTS.TITLES.ABFUELLUNG.FL);
      });

      this._selectSpruehdose.bind('click keypress', function(ev)
      {
        jQuery(self).trigger('selectPackage', { 'id': self._id, 'mode' : ff.PackageSelect.SPRUEHDOSE });
        self.setHeadline('Abf&uuml;llung: ' + FF_CONFIG.CALLOUTS.TITLES.ABFUELLUNG.SD);
      });

      this._selectLackstift.bind('click keypress', function(ev)
      {
        jQuery(self).trigger('selectPackage', { 'id': self._id, 'mode' : ff.PackageSelect.LACKSTIFT });
        self.setHeadline('Abf&uuml;llung: ' + FF_CONFIG.CALLOUTS.TITLES.ABFUELLUNG.LS);
      });
    },
    setId: function(id)
    {
      this._id = id;
    },
    setQuality: function(quality)
    {
      this._quality = quality;
      if(this._quality == ff.QualitySelect.QUALITY_WASSERLACK)
      {
        this._selectLackstift.css('display', 'none');
      }
      else
      {
        this._selectLackstift.css('display', 'block');
      }

      if(this._options.default_package)
      {
        switch(this._options.default_package)
        {
          case ff.PackageSelect.ANDERE_ABFUELLUNG:
            jQuery(this).trigger('selectPackage', { 'id': this._id, 'mode' : ff.PackageSelect.ANDERE_ABFUELLUNG });
            this.setHeadline('Abf&uuml;llung: ' + FF_CONFIG.CALLOUTS.TITLES.ABFUELLUNG.FL);
            return false;
          case ff.PackageSelect.SPRUEHDOSE:
            jQuery(this).trigger('selectPackage', { 'id': this._id, 'mode' : ff.PackageSelect.SPRUEHDOSE });
            this.setHeadline('Abf&uuml;llung: ' + FF_CONFIG.CALLOUTS.TITLES.ABFUELLUNG.SD);
            return false;
          case ff.PackageSelect.LACKSTIFT:
            jQuery(this).trigger('selectPackage', { 'id': this._id, 'mode' : ff.PackageSelect.LACKSTIFT });
            this.setHeadline('Abf&uuml;llung: ' + FF_CONFIG.CALLOUTS.TITLES.ABFUELLUNG.LS);
            return false;
        }
      }
      return true;
    },
    resetHeadline: function()
    {
      this._headline.html(this._headlineHtml);
    },
    setHeadline: function(headline)
    {
      this._headline.html(headline);
    }
  });
})();


