/*
  BarackSlideshow 0.1
    - Libraries required: MorphList <http://devthought.com>
    - MooTools version required: 1.2
    - MooTools components required: 
        Core: (inherited from MorphList)
        More: Assets
  
    Changelog:
    - 0.1: First release
*/
/*! Copyright: Guillermo Rauch <http://devthought.com/> - Distributed under MIT - Keep this message! */

var MenuSlide = new Class({
  
  Extends: MorphList,
  
  options: {/*
    onShow: $empty,*/
  },
  
  initialize: function(menu, slides, loader, options) {

    this.parent(menu, options);
    this.slides = $(slides);
    this.slidesitems = this.slides.getChildren();
    if(options && options.onClick){
    	this.addEvent('onClick',options.onClick);
    }
    /** This will show the first item in the list, the tWWF news. **/
    this.show(0);
  },
  			
  click: function(ev, item) {
    this.parent(ev, item);
    new Event(ev).stop();
    this.show(this.menuitems.indexOf(item));
  },
  
  show: function(index) {
    var slide = this.slidesitems[index];    
		if(slide == this.curslide) return;
	
	if(this.curslide) this.curslide.removeProperty('id');
	slide.setProperty('id','selected_slide');
	
    slide.dispose().fade('hide').inject(this.curslide || this.slides.getFirst(), this.curslide ? 'after' : 'before').fade('in');
		slide.setStyle('display', 'block');
    $pick(this.curslide, slide).get('tween').chain(function() { this.fireEvent('onShow', slide); }.bind(this));
    this.curslide = slide;
		return this;
  }
  
});