

function Gallery() {
	this.current = false;
	this.length = false;
	this.page = false;
}

Gallery.prototype.setData = function(data) {
	this.data = data;
	this.length = data.length;
}

Gallery.prototype.showThumbnails = function(page) {
	if (typeof page == 'undefined') page = 1;
	
	// make sure page isn't out of range
	var c = (page-1) * 12;
	if (c >= this.length || c < 0) return false;
	this.page = page;
	var thumbrows = $('thumbnails').getElementsByTagName('tr');
	var thumbcells, i, j
	for (i=0; i<thumbrows.length; i++) {
		thumbcells = thumbrows[i].getElementsByTagName('td');
		for (j=0; j<thumbcells.length; j++) {
			if (!this.data[c]) {
				thumbcells[j].innerHTML = '';
			} else {
				thumbcells[j].innerHTML = '<a href="#" onclick="gallery.setImage('+c+'); return false;"><img src="'+this.data[c].thumbnail+'" alt="'+this.data[c].title+'" /></a>';
				c++;
			}
		}		
	}
}

Gallery.prototype.nextThumbnails = function() {
	if (this.page < this.length-1) {
		this.page++;
		this.showThumbnails(this.page);
	}
}

Gallery.prototype.prevThumbnails = function() {
	if (this.page >= 2) {
		this.page--;
		this.showThumbnails(this.page);
	}
}

Gallery.prototype.setImage = function(i) {
	this.current = i;
	var d = this.data[i];
//	$('image_credit').innerHTML		= d.credit;
//	$('image_title').innerHTML			= d.title;
//	$('image_description').innerHTML = d.description;
	$('image_image').src					= d.image;
}

Gallery.prototype.next = function() {
	if (this.current === false) {
		this.current = 0;
	} else if (this.current < (this.length-1)) {
		++this.current;
	} else {
		return false;
	}
	return this.setImage(this.current);
}

Gallery.prototype.prev = function() {
	if (this.current > 0) {
		--this.current;
	} else if (this.current == 0) {
		this.current = this.length-1;
	} else {
		return false;
	}
	return this.setImage(this.current);
}


