(function($)
{
	$.fn.gallery = function(options)
	{
		// Set the options.
		options = $.extend({}, $.fn.gallery.defaults, options);

		// Go through the matched elements and return the jQuery object.
		return this.each(function()
		{
			// hide captions
			$(options.caption).hide();
			
			$(options.stage)
				.find('img')
					// hover event to show caption on stage
					.hover(
						function()
						{
							$(options.caption).fadeIn('slow');
						},
						function()
						{
							$(options.caption).fadeOut('slow');
						}
					);
			
			$(this)
				.find("img")
				.each(
					function(){
						// make transparent
						$(this)
							.css('opacity', options.opacity);
					
						// highlight on hover
						$(this)
							.hover(
								function(){
									$(this).fadeTo('500', 1);
								},
								function(){
									$(this).fadeTo('500', options.opacity);
								}
							);
					
					
						// bind click function
						$(this)
							.click(
								function(){
									
									// get thumb path
									var path = $(this).attr('src');
									
									var thumb = $(this);
									
									// replace with full path
									path = path.replace(options.thumb_dir, options.full_dir);
									
									// change stage image path
									$(options.stage)
										.fadeOut('slow', function(){											
											
											// set img src
											$(this).find('img')
												.attr('src', path)
												.attr('title', thumb.attr('title'))
												.attr('alt', thumb.attr('alt'));
											
											// set caption
											$(options.caption).text(thumb.attr('title'));
											
											// fade back in
											$(this).fadeIn('slow');
										});
									
									$(this).css('opacity', 1);
									
									// prevent click follow through
									return false;
								}
							);
					}
				);
		
		});
	};
	// Public defaults.
	$.fn.gallery.defaults = {
		stage: '#gallery-stage',
		caption: '#gallery-stage .caption',
		thumb_dir: '/images/thumb/',
		full_dir: '/images/large/',
		opacity: 0.3
	};
	// Private functions.
	function func()
	{
		return;
	};
	// Public functions.
	$.fn.gallery.func = function()
	{
		return;
	};
})(jQuery);
