/* Morph.js contents */

var MorphList = new Class({   
	
	Implements: [Events, Options],
	
	options: {/*             
		onmouseover: $empty,
		onMorph: $empty,*/
		morph: { 'link': 'cancel' }
	},
	
	initialize: function(menu, options) {
		var that = this;
		this.setOptions(options);
		this.menu = $(menu);
		this.menuitems = this.menu.getChildren("li:not(.title)");
		this.menuitems.addEvents({
			mouseenter: function(){ that.morphTo(this); },
			mouseleave: function(){ that.morphTo(that.current); },
			mouseover: function(ev){ that.mouseover(ev, this); }
		});       
		//this.bg = new Element('li', {'class': 'background'}).adopt(new Element('div', {'class': 'left'}));
		//this.bg.fade('hide').inject(this.menu).set('morph', this.options.morph);
		this.setCurrent(this.menu.getElement('.current'));
	},          

	mouseover: function(ev, item) {
		this.setCurrent(item, true);
		this.fireEvent('onmouseover', [ev, item]);
	},
	
	setCurrent: function(el, effect){  
		//if(el && ! this.current) {
			//this.bg.set('styles', { left: el.offsetLeft, width: el.offsetWidth, height: el.offsetHeight, top: el.offsetTop });
			//(effect) ? this.bg.fade('hide').fade('in') : this.bg.setOpacity(1);
		//}
		if(this.current) this.current.removeClass('current');
		if(el) this.current = el.addClass('current');    
	},         
         
	morphTo: function(to) {
		if(! this.current) return; 
		//this.bg.morph({
			//left: to.offsetLeft, top: to.offsetTop,
			//width: to.offsetWidth, height: to.offsetHeight
		//});
		this.fireEvent('onMorph', to);
	}

});


/* Slidshow JS*/

var BarackSlideshow = new Class({
  
  Extends: MorphList,
  
  options: {/*
    onShow: $empty,*/
  },
  
  initialize: function(menu, images, loader, options) {
    this.parent(menu, options);
    this.images = $(images);
    this.imagesitems = this.images.getChildren();
    this.imagesitems.fade('hide');
    $(loader).fade('in');
    new Asset.images(this.images.getElements('img').map(function(el) { return el.setStyle('display', 'none').get('src'); }), { onComplete: function() {
      this.loaded = true;      
      $(loader).fade('out');
      if(this.current) this.show(this.menuitems.indexOf(this.current));
    }.bind(this) });
  },
  			
  mouseover: function(ev, item) {
    this.parent(ev, item);
    new Event(ev).stop();
    this.show(this.menuitems.indexOf(item));
  },
  
  show: function(index) {
    if(! this.loaded) return;
    var image = this.imagesitems[index];    
		if(image == this.curimage) return;
    image.dispose().fade('hide').inject(this.curimage || this.images.getFirst(), this.curimage ? 'after' : 'before').fade('in');
		image.getElement('img').setStyle('display', 'block');
    $pick(this.curimage, image).get('tween').chain(function() { this.fireEvent('onShow', image); }.bind(this));
    this.curimage = image;
		return this;
  }
  
});

/* Initialize */

window.addEvent('domready', function() {
  new BarackSlideshow('menu', 'pictures', 'loading', 'picture');
  
  $('featureNameBox').innerHTML = "&nbsp;";
		$('featureDirectorsNameBox').innerHTML = "&nbsp;";

$$('.featuresClicker').each(function(thisLink){
	//alert(thisLink);
	thisLink.addEvent('mouseover',function(){
		$('featureNameBox').innerHTML = thisLink.get('rel');
		$('featureDirectorsNameBox').innerHTML = thisLink.get('alt');
		$('pictures').setStyle('background','none');
	});
});
  
});


