var photoGallery = Class.create();
photoGallery.prototype = {
	
	initialize: function( elm, p){
		e = $(elm);
		if( e ){
			this.images = new Array();
			this.nextButtons = new Array();
			this.prevButtons = new Array();
			
			this.numPhotos = p.length;
			for( i=0; i<this.numPhotos; i++){
				var t = new Image();
				t.src = p[i];
				this.images.push(t);
			}
			this.currentIndex = 0;
			var c = '#' + elm + ' .image_container img';
			this.image_elm = $$(c)[0];
			
			c = '#' + elm + ' .navigation .previous';
			c = $$(c);
			var l = c.length;
			for( i=0; i<l; i++){
				this.prevButtons.push(c[i]);
				c[i].observe('click', this.prevImage.bindAsEventListener(this));
				c[i].onclick = function(){ return false;}
			}
			c = '#' + elm + ' .navigation .next';
			c = $$(c);
			l = c.length;
			for( i=0; i<l; i++){
				this.nextButtons.push(c[i]);
				c[i].observe('click', this.nextImage.bindAsEventListener(this));
				c[i].onclick = function(){ return false;}
			}
			return true;
		}else{
			return false;
		}
	},
	
	nextImage: function(){
		this.currentIndex++;
		if( this.currentIndex >= this.numPhotos ){
			this.currentIndex = 0;
		}
		this.image_elm.src = this.images[this.currentIndex].src;
	},
	
	prevImage: function(){
		this.currentIndex--;
		if( this.currentIndex < 0 ){
			this.currentIndex = this.numPhotos - 1;
		}
		this.image_elm.src = this.images[this.currentIndex].src;
	}
	
}

