/*
/|	Bookrotator, written for www.age-of-media.com by Lukas Rieder
*/

var bookrotator = new Class({
	initialize: function(element, interval){
		this.interval=interval;
		
		this.wrapper = element.set({
			'styles':{
				position:'relative',
				overflow:'hidden'
			}
		});
		
		this.books = this.wrapper.getChildren('.book');
		this.heights=[];
		this.books.each(function(element, index){
			this.heights.include(element.getCoordinates().height);
		}, this);
		this.books.setStyle('position', 'absolute').fade('hide');
		
		this.current=0;
		this.show();
		this.play();
	},
	play: function(){
		this.autoPlay = this.auto.periodical(this.interval, this);
	},
	stop: function(){
		$clear(this.autoPlay);
	},
	auto: function(){
		this.hide();
		if(this.current>=this.books.length-1){
			this.current=0;
		}else{
			this.current+=1;
		}
		this.show();
	},
	show: function(){
		this.wrapper.tween('height', this.wrapper.getCoordinates().height, this.heights[this.current]);
		this.books[this.current].fade('in');
	},
	hide: function(){
		this.books[this.current].fade('out');
	}
});
window.addEvent('domready', function() {
	var Interval = 6000;
	var rotate = new bookrotator($('books'), Interval);
});