Gallery = function(imageHolder, imageWrapper, imageCountHolder, nextButton, prevButton) {

	this.currentImage = 0;
	this.imageHolder = imageHolder;
	this.imageWrapperWidth = imageWrapper[0].offsetWidth;
	this.imageCountHolder = imageCountHolder;
	this.maxCount = imageWrapper.length,
	this.nextButton = nextButton;
	this.prevButton = prevButton;
	
	this.init = function() {
		// 
		this.attachEvents();
	}
	
	this.attachEvents = function() {
		// write next/prev functions
		var that = this;
		if(this.nextButton) {
			this.nextButton.click(function() {
				that.next();
				this.blur();
				return false;
			});
		}
		if(this.prevButton) {
			this.prevButton.click(function() {
				that.previous();
				this.blur();
				return false;
			});
		}
	}
	
	this.updateCount = function(newCount) {
		// set current image
		this.currentImage = newCount;
		//
		var newCountPrefix = (newCount < 9) ? "0" : "";
		var maxCountPrefix = (this.maxCount < 9) ? "0" : "";
		// update current image display
		if(this.imageCountHolder) this.imageCountHolder.innerHTML = newCountPrefix + "" + (newCount + 1) + "/" + maxCountPrefix + this.maxCount;
		// update url
		//window.location.hash = (newCount + 1);
	}
	
	this.init();
}

Gallery.prototype.gotoImage = function(num) {
	// if not too high
	if(num >= this.maxCount) num = 0;
	if(num < 0) num = (this.maxCount -1);
	if(num < this.maxCount && num >= 0) {
		// animate holder
		this.imageHolder.animate({
			marginLeft: (num * this.imageWrapperWidth) * -1 + "px"
		}, 600);
		// update count
		this.updateCount(num);
	}
}

Gallery.prototype.next = function() {
	// show next image
	this.gotoImage(this.currentImage + 1);
}

Gallery.prototype.previous = function() {
	// show previous image
	this.gotoImage(this.currentImage - 1);
}