/*
  CategorySlide Class
  Originally developed by Valerio Proietti for http://www.mootools.net/, copyright ©2006
  Modified for Mootools v1.2 by Stewart Laufer
  copyright ©2008 tectonyc  
*/
var CategorySlide = new Class({
  options: {
    container: null,
    category_menu_id: null,
    category_class: null,
    maximum_size: null,
    minimum_size: null,
    default_size: null
  },
  initialize:function(options){
    this.setOptions(options);
    this.maximum_size = this.options.maximum_size;
    this.minimum_size = this.options.minimum_size;
    this.default_size = this.options.default_size;
    this.container = $(this.options.container);
    this.category_menu_container = $(this.options.category_menu_id).id;
    this.category_class = this.options.category_class;
    this.items = $$("#"+this.options.container+" ."+this.category_class);
    this.items_fx = new Fx.Elements(this.items, {wait: false, duration: 200});
    this.currently_opened = null;
    this.initialize_rollovers();
    this.initialize_rollovers.bind(this);
    this.container.addEvent('mouseleave',this.initialize_rolloffs.bindWithEvent(this));
  },
  initialize_rollovers:function(){
    var slider = this;
    var categories = this.items;
    categories.each(function(category, index){
      category.addEvent('mouseenter',function(event){
        e = new Event(event).stop();
        var elements = {};
        elements[index] = {
          'width': [category.getStyle('width').toInt(), this.maximum_size]
        };
        categories.each(function(other, other_index){
          if (other != category){
            var width = other.getStyle('width').toInt();
            if (width != this.minimum_size) {
              elements[other_index] = {
                'width': [width, this.minimum_size]
              };
            }
          }
        }.bind(this));
        this.fireEvent('beforeOpen',this.currently_opened);
        this.items_fx.start(elements, {transition: Fx.Transitions.quadOut}).chain(function(){
          slider.currently_opened = category;
          slider.fireEvent('afterOpen',category);
        });
      }.bind(this));
    }.bind(this));
  },
  initialize_rolloffs:function(){
    var slider = this;
    this.fireEvent('beforeCloseAll',this);
    var categories = this.items;
    var elements = {};
    categories.each(function(other_category, other_index){
      elements[other_index] = {
        'width': [other_category.getStyle('width').toInt(), this.default_size]
      };
    }.bind(this));
    this.items_fx.start(elements, {transition: Fx.Transitions.quadOut}).chain(function(){
      slider.fireEvent('afterCloseAll',this);
    });
  }
});

CategorySlide.implement(new Options, new Events);