// Unobtrusively set up the floorplan's "mini-gallery"
// 
function minigallery() {
	// Make the mini-gallery-ctl div visible (if necessary)
	$('.mini-gallery-ctl').css("visibility", "visible");

	// Turn off all but the first image in the "mini-gallery" and
	// highlight the selected image in the "button" list. Must be
	// handled in an .each() construct for gt(...) and eq(...) to work.
	$('.plan-details').each(function() {
		$(this).find('.mini-gallery img:gt(0)').css('display', 'none');
		$(this).find('.mini-gallery img:eq(0)').addClass('current');
		$(this).find('.mini-gallery-nav span:eq(0)').addClass('selected');
	});
	
	// Associate the switch with its image using class and ID names,
	// and assign a click event to each switch. Every switch is assigned 
	// a unique class name that matches the name of the unique ID assigned
	// to its image, so the switch w/ the 'galleryimg5' class will toggle
	// the display of the image with the 'galleryimg5' ID.
	var imgset = $('.mini-gallery img');
	var switchset = $('.mini-gallery-nav span');
	var idx = 0;
	var limit = switchset.size();
	while(idx < limit) {
		var conn = 'galleryimg' + idx;
		$(imgset.get(idx)).attr('id', conn);  // Assign the image ID
		$(switchset.get(idx)).addClass(conn); // Assign the switch class
		$(switchset.get(idx)).click(function() {
			$(this).parent().siblings().find('.selected').removeClass('selected');
			$(this).addClass('selected');
			var imgId = '#' + $(this).attr('class').match(/galleryimg[0-9]*/);
			$(imgId).siblings('.current').css('display', 'none').removeClass('current');
			$(imgId).addClass('current').css('display', 'block');
		});
		idx++;
	}
}

