$(document).ready(function() {
	Gallery = {
		currentImage: 0,
		imageHolderWidth: 704,
		maxCount: $("div.folio-image").length,
		next: function() {
			// show next image
			this.gotoImage(this.currentImage + 1);
		},
		previous: function() {
			// show previous image
			this.gotoImage(this.currentImage - 1);
		},
		updateCount: function(newCount) {
			// set current image
			this.currentImage = newCount;
			// update current image display
			$("div#gallery-navigation").children("p:eq(1)").html((newCount + 1) + "/" + this.maxCount);
			// update url
			window.location.hash = (newCount + 1);
		},
		gotoImage: function(num) {
			// if not too high
			if(num < this.maxCount && num >= 0) {
				// store holder
				var holder = $('div#folio-gallery-wrapper');
				// animate holder
				holder.animate({
					marginLeft: (num * this.imageHolderWidth) * -1 + "px"
				}, 600);
				// update count
				this.updateCount(num);
			} else {
				if(num == this.maxCount) {
					// go to next project
					this.gotoImage(0);
				} else if(num > this.maxCount) {
					// assume it is coming in through the URL and set currentImage to 0
					this.updateCount(0);
				} else {
					// go to previous project
					this.gotoImage(this.maxCount - 1);
				}
			}
		}
	}
});