$.thumbs = [];

$.Gallery = function (el) {

	var me = this;
	var $element = this.$element = $(el);
	var $containerFoto = $("#fotos-fotao td");

	this.show = function(e) {
		if($containerFoto.find('img').attr("src") != $element.find('a').attr('href')){
			
			$("#fotos-thumbs li a").css("opacity",1);
			$(e.target).parent().css("opacity",.5);
			
			$containerFoto.find('img')
				.fadeTo('fast', .01)
				.queue(function () {
					$(this)
					.dequeue()
					.attr('src', $element.find('a').attr('href'));
				});
			$("#fotos .legenda span").text($element.find('a img').attr('longdesc'));
		}
	};

	this.click = function (e) {
		me.show(e);
		e.preventDefault();
	};
	
	this.bindclick = function(e){
		$element.find('a').bind("click",this.click);
	};
	
	this.unbindclick = function(){
		$element.find('a').unbind("click");
	};
	
	this.bindclick();
};

(function($){
	$(function (){
		var $element = $("#fotos-thumbs li");
		
		$element.pontoscroll();
		
		$("#fotos-fotao td").find('img').bind("load", function (e) { $(this).fadeTo('fast', 1) });
		
		$element.each(function (idx, el) {
			$.thumbs.push(new $.Gallery(el));
		});
	});
})(jQuery);
