$(function(){
	/* Initialize the gallery */
	gallery.init();
})

var gallery = {
	
	photoQty:20,
	currentPhoto:1,
	btnPreviousSelector:"#btn_previous a",
	btnNextSelector:"#btn_next a",
	
	
	init:function(){		
		this.events();
	},
	
	events:function(){
	
		var _this = this;			
		/* Create the listener for the next button anchor */
		$(this.btnNextSelector).click(function(){
			if (_this.currentPhoto < 20) {
				_this.currentPhoto++;
			}			
			_this.show(_this.currentPhoto);
			_this.displayCurrentPhoto(_this.currentPhoto);
			return false;
		});	
		
		/* Create the listener for the previous button anchor */
		$(this.btnPreviousSelector).click(function(){
			if (_this.currentPhoto != 1) {
				_this.currentPhoto--;
			}
			_this.show(_this.currentPhoto);
			_this.displayCurrentPhoto(_this.currentPhoto);			
			return false;
		});		
	},
	
	/* Display and image hide the previous and the next */
	show:function(id){
		$("#photo_"+id).show();
		if(id>=1){
			this.hide(id-1);
			this.hide(id+1);
		}
	},
	
	/* Hide an image */
	hide:function(id){
		$("#photo_"+id).hide();
	},
	
	/* Set the counter image with the current photo */
	displayCurrentPhoto:function(id){
		$("span#currentPhoto").text(id);
	}
	
}
