$(document).ready(function() {
	new Gallery('.galleryimage','#gallerytriggers','#gallerylabel');
});



var Gallery = function(photo,triggers,label) {
	this.photo = $(photo + ' img');
	this.triggers = $(triggers + ' a');
	this.selLink = $(triggers + ' a.selected');
	this.label = $(label);
	this.activateTriggers();
}

Gallery.prototype = {
	photo:'',
	triggers:'',
	selLink:'',
	activateTriggers:function() {
		var me = this;
		$.each(this.triggers,function() {
			$(this).attr({'rel': $(this).attr('href')});
			$(this).attr({'href': 'javascript:void(0);'});
			$(this).bind('click',function(){
				me.switchPhotos($(this).attr('rel'));
				me.setSelected($(this));
				me.setLabel();
			});
		});
	},
	switchPhotos:function(newphoto) {
		var me = this;
		this.photo.fadeOut('slow', function(){
			me.photo.attr({'src': newphoto}); // Fade in the image.
			me.photo.fadeIn('slow');
		});
	},
	setSelected:function(obj) {
		this.setLinkViews(obj);
		this.selLink.toggleClass('selected');
		obj.toggleClass('selected');
		this.selLink = obj;
	},
	setLabel:function() {
		var str = this.parseLabel(this.selLink.attr('id'));
		this.label.html(str);
	},
	parseLabel:function(str) {
		return str.replace(/_/g,' ');
	},
	setLinkViews:function(obj) {
	}
}
