var SimpleGallery = null;

$(function() {
	SimpleGallery = new _SimpleGallery("img.sg-big-pic", "a.sg-thumbnail");
});

_SimpleGallery = function(bigPicSelector, thumbnailsSelector) {
	this.bps = $(bigPicSelector);
	this.ts = $(thumbnailsSelector);

	this.setup();
};

_SimpleGallery.prototype = {
	setup: function() {
		this.setListeners();
		this.onStart();
	},

	setListeners: function() {
		var parent = this;
		this.ts.each(function() {
			var el = $(this).css("cursor", "pointer");
			el.click(function() {
				parent.bps.attr("src", parent.getLink(el));
				return false;
			});
		});
	},

	getLink: function(domEl) {
		if(!domEl.attr("href")) {
			link = domEl.children().filter("img").attr("src");
		} else {
			link = domEl.attr("href");
		}

		return link;
	},

	onStart: function() {
		this.bps.attr("src", this.getLink($(this.ts[0])));
	}
};
