var photoSlider = new Class({
	
	Implements: Options,
		options: {
	},

	currentPosition : 	1,
	prevPosition	:	1,
	maxItems 		: 	27,
	zindex			:	1,
	
	initialize: function(options){

		this.setOptions(options);
		this.nextItem.periodical( 3000, this );
		this.currentPosition = Math.round((Math.random()*(this.maxItems-1)))+1;
		$$('photoslider').each( function(td) {
			td.style.zIndex = 0;
		});
		$(this.options.id+this.currentPosition).style.zIndex = 1;
		
	},
	
	nextItem: function() {
		if( this.currentPosition > 0 ) {
			this.prevPosition = this.currentPosition;
			this.currentPosition++;
			if( this.currentPosition > this.maxItems ) {
				this.currentPosition = 1;
			}
			this.changeCarousel();
		}
	},
	
	changeCarousel: function() {
		//alert('photo'+ this.currentPosition);
		if( this.zindex > 3 ) {
        	for( var i = 1; i <= this.maxItems; i++ ) {
	        	$(this.options.id+i).style.zIndex = (i == this.prevPosition) ? 1 : 0 ;
	        }
	        this.zindex = 1;
        }
        this.zindex++;
        $(this.options.id+this.currentPosition).fade('hide');
        $(this.options.id+this.currentPosition).style.zIndex = this.zindex;
        $(this.options.id+this.currentPosition).fade('in');
	}
	

});

window.addEvent('domready', function() {

	photoSlider = new photoSlider({
		id: 'photo'	
	});
	
});
