/*!
 * AMteam programmeurs + vormgevers
 */
SlideShow.defineTransition('custom', function(data) {
	var half = data.duration / 2,
			tweenOptions = {
				duration: half,
				transition: 'quad:in:out'
			},
			image = {
				next: data.next.getElement('img'),
				previous: data.previous.getElement('img')
			},
			caption = {
				next: data.next.getElement('figcaption'),
				previous: data.previous.getElement('figcaption')
			};
	
	// Slide image
	image.next.set('tween', tweenOptions).setStyle('top', image.next.getHeight());
	image.previous.set('tween', tweenOptions).tween('top', image.previous.getHeight());
	setTimeout(function() {
		image.next.tween('top', 0);
	}, half);
	
	// Fade caption
	caption.next.set('tween', tweenOptions).fade('hide')
	caption.previous.set('tween', tweenOptions).fade('out');
	setTimeout(function() {
		caption.next.fade('in');
	}, half);
});

SlideShow.implement('addControls', function() {
	// Add controls
	var controls = this.slides.map(function(slide, i) {
		return new Element('li', {
			'text': i + 1,
			'class': i == this.index ? 'active' : null,
			'events': {
				click: function() {
					this.show(i);
				}.bind(this)
			}
		});
	}, this);
	this.element.grab(new Element('ul.controls').adopt(controls));

	// Add events
	this.addEvent('show', function(data) {
		controls[data.previous.index].removeClass('active');
		controls[data.next.index].addClass('active');
	});

	this.element.addEvents({
		'mouseenter': function() {
			this.pause();
		}.bind(this),
		'mouseleave': function() {
			this.play();
		}.bind(this)
	});

	return this;
});
