var flickrFeed = new Class({
	Implements: [Events, Options],
	options:{
		btnLeft:'flickr-left',
		btnRight:'flickr-right',
		imgClass:'#imgholder img'
	},
	initialize:function(options){
		this.setOptions(options);
									
		//determine number of images
		this.imageCount = $$(this.options.imgClass).length;
		this.currentImageIndex = 0;
		
		if(this.imageCount > 0){
			//hide all images, then show the first
			$$(this.options.imgClass).setStyle('opacity',0);
			$$(this.options.imgClass)[0].tween('opacity',[0,1]);
			
			//assign navigation behaviour
			$(this.options.btnLeft).addEvent('click',function(){
				this.prevImage()
			}.bind(this));
			$(this.options.btnRight).addEvent('click',function(){
				this.nextImage()
			}.bind(this));
		}
	},
	
	prevImage:function(){
		$$(this.options.imgClass)[this.currentImageIndex].tween('opacity',[1,0]);
		if(this.currentImageIndex - 1 < 0){
			this.currentImageIndex = this.imageCount - 1;
		} else {
			this.currentImageIndex = this.currentImageIndex - 1;
		}
		$$(this.options.imgClass)[this.currentImageIndex].tween('opacity',[0,1]);				
	},
	
	nextImage:function(){	
		$$(this.options.imgClass)[this.currentImageIndex].tween('opacity',[1,0]);
		if(this.currentImageIndex + 1 >= this.imageCount){
			this.currentImageIndex = 0;
		} else {
			this.currentImageIndex = this.currentImageIndex + 1;
		}							
		$$(this.options.imgClass)[this.currentImageIndex].tween('opacity',[0,1]);				
	}
	
});



window.addEvent('domready',function(){
	var flickr = new flickrFeed({imgClass:'#imgholder .imageblock'});			
});