document.observe('dom:loaded', function() { PhotoController.init(); });

PhotoController = {
	
	view: null,
	allPhotos: null,
	currentPhoto: null,
	currentPhotoIndex: null,
	
	init: function() {
		this.view = $('photo_box');
		this.allPhotos = this.view.select('.photo');
		
		var randomNumber = Math.floor(Math.random()*this.allPhotos.length)
		this.currentPhoto = this.allPhotos[randomNumber];
		
		this.allPhotos.invoke('hide');
		this.currentPhoto.show();
//		this.currentPhotoIndex = this.view.select('.photo').indexOf(this.currentPhoto);
	},
	
	nextPhoto: function(params) {
		this.currentPhoto.fade({ duration: 1 });
		
		if(this.currentPhoto.next('.photo'))
			this.currentPhoto = this.currentPhoto.next('.photo');
		else
			this.currentPhoto = this.allPhotos.first();
		
		this.currentPhoto.appear({ duration: 1 });
	},
	
	previousPhoto: function(params) {
		this.currentPhoto.fade({ duration: 1 });
		
		if(this.currentPhoto.previous('.photo'))
			this.currentPhoto = this.currentPhoto.previous('.photo');
		else
			this.currentPhoto = this.allPhotos.last();
		
		this.currentPhoto.appear({ duration: 1 });
	}
};

