var programmaSlider = new Class({

	currentDay: 1,
	maxDays: 9,
	sizeDay: 255,
	sizeLine: 27,
	sizeTitle: 40,
	
	initialize: function() {
		this.dayFx = new Fx.Tween( 'programma', {duration: 300} );
		this.lineFx = new Fx.Tween( 'programma-dagen', {duration: 200} );
		this.titleFx = new Fx.Tween( 'title-wrapper', {duration: 200} );
		
		$( 'arrow-left' ).addEvent( 'click', this.previousDay.bind( this ));
		$( 'arrow-right' ).addEvent( 'click', this.nextDay.bind( this ));
		
		var i = 1;
		while( i <= this.maxDays ) {
			$( 'li' + i ).addEvent( 'click', this.setDay.pass( i, this ));
			i++;
		}
		
		this.dayFx.start( 'left', -this.sizeDay * ( this.currentDay - 1 ));
		$('programma-dagen').setStyle('background-position', '0 72px');
		this.titleFx.start( 'top', -this.sizeTitle * ( this.currentDay - 1 ));

	},

	previousDay: function() {
		previousDay = this.currentDay + ( this.currentDay > 1 ? -1 : this.maxDays - 1 );
		this.dayFx.start( 'left', -this.sizeDay * ( previousDay - 1 ));
		this.lineFx.start( 'background-position', "0 " + ( 72 + this.sizeLine * ( previousDay - 1 )) + "px" );
		this.titleFx.start( 'top', -this.sizeTitle * ( previousDay - 1 ));
		this.currentDay = previousDay;	
	},
	
	nextDay: function() {
		nextDay = this.currentDay + ( this.currentDay < this.maxDays ? 1 : 1 - this.maxDays );
		this.dayFx.start( 'left', -this.sizeDay * ( nextDay - 1 ));
		this.lineFx.start( 'background-position', "0 " + ( 72 + this.sizeLine * ( nextDay - 1 )) + "px" );
		this.titleFx.start( 'top', -this.sizeTitle * ( nextDay - 1 ));
		this.currentDay = nextDay;
	},
	
	setDay: function( day ) {
		this.dayFx.start( 'left', -this.sizeDay * ( day - 1 ));
		this.lineFx.start( 'background-position', "0 " + ( 72 + this.sizeLine * ( day - 1 )) + "px" );
		this.titleFx.start( 'top', -this.sizeTitle * ( day - 1 ));
		this.currentDay = day;
	}
});


window.addEvent('domready', function() {
	var programma = new programmaSlider();
});
