(function (jQuery) {
	jQuery.fn.Gallery = function () {
				
		return jQuery(this).each(function() {
			
			var t = this;
			
			jQuery('a', t).click(function() {
				
				var i = $(this).attr('href');
				i = i.replace(/.*image=([0-9]*.*)/i, "$1")
				
				var v = $('.main a:visible', t);
				
				if (v.attr('class') != 'picture_' + i)
				{
					v.fadeOut(500);
					$('.thumbs a.active').each(function() {
						if (!$(this).hasClass('next'))
							$(this).removeClass('active').addClass('normal');
					});
					$('.picture_' + i, t).fadeIn(500);
					$('.thumb_' + i, t).removeClass('normal').addClass('active');
					
					$('.next', t).attr('href', $('.picture_' + i, t).attr('href'));
				}
				return false;
			});

		});
	}
	
})(jQuery);
