var GALLERY_IMAGES = new Array();
	GALLERY_IMAGES["reno_1700"] = 6;
	GALLERY_IMAGES["reno_cross"] = 9;
	GALLERY_IMAGES["reno_kitchen"] = 6;
	GALLERY_IMAGES["reno_country"] = 4;
	GALLERY_IMAGES["reno_riverhouse"] = 7;
	GALLERY_IMAGES["additions_weekend"] = 6;
	GALLERY_IMAGES["additions_horse"] = 6;
	GALLERY_IMAGES["additions_riverhouse"] = 5;
	GALLERY_IMAGES["additions_jacuzzi"] = 8;
	GALLERY_IMAGES["additions_elbow"] = 4;
	GALLERY_IMAGES["new_meadows"] = 11;
	GALLERY_IMAGES["new_tinkertown"] = 2;
	GALLERY_IMAGES["new_hollow"] = 4;
	GALLERY_IMAGES["new_retirement"] = 5;
	GALLERY_IMAGES["energy_solarthermal"] = 3;
	GALLERY_IMAGES["energy_solarelectric"] = 2;
	GALLERY_IMAGES["energy_plan"] = 6;
	GALLERY_IMAGES["energy_insulation"] = 3;
	GALLERY_IMAGES["comm_rivergate"] = 5;
	GALLERY_IMAGES["comm_village"] = 3;
	GALLERY_IMAGES["comm_valeria"] = 3;
	GALLERY_IMAGES["comm_millbrook"] = 4;

function initGallery(tab) {
	$('ul.gallery').galleria({
		clickNext : true, // helper for making the image clickable
		insert    : '#main-image-'+tab, // the containing selector for our main image
		thumb_crop: false,
		onImage   : function(image,caption,thumb) { // let's add some image effects for demonstration purposes
		
			// fade in the image & caption
			if(! ($.browser.mozilla && navigator.appVersion.indexOf("Win")!=-1) ) { // FF/Win fades large images terribly slow
				image.css('display','none').fadeIn(1000);
			}
			caption.css('display','none').fadeIn(1000);
			
			// fetch the thumbnail container
			var _li = thumb.parents('li');
			
			// fade out inactive thumbnail
			_li.siblings().children('img.selected').fadeTo(500,0.3);
			
			// fade in active thumbnail
			thumb.fadeTo('fast',1).addClass('selected');
			
			// add a title for the clickable image
			image.attr('title','Next image >>');
		},
		onThumb : function(thumb) { // thumbnail effects goes here
			
			// fetch the thumbnail container
			var _li = thumb.parents('li');
			
			// if thumbnail is active, fade all the way.
			var _fadeTo = _li.is('.active') ? '1' : '0.3';
			
			// fade in the thumbnail when finnished loading
			thumb.css({display:'none',opacity:_fadeTo}).fadeIn(1500);
			
			// hover effects
			thumb.hover(
				function() { thumb.fadeTo('fast',1); },
				function() { _li.not('.active').children('img').fadeTo('fast',0.3); } // don't fade out if the parent is active
			)
		}
	});
}

function bindSectionNav(tab) { 
	$('.section-nav').each(function() { 
		$(this).click(function() {
			$('#waiting_ajax_dialog').jqmShow();
			var section = $(this).attr("rel");
			clearSectionHighlights(tab);
			$(this).html('<img src="/projects/site-images/'+tab+'_'+$(this).attr("rel")+'_over.png" alt="" border="0" />');
			var imgcount = GALLERY_IMAGES[tab+'_'+section];
			$('ul.gallery').each(function() { $(this).html(""); });
			$('div.gallery-body').each(function() { $(this).html(""); });
			for(var i=1; i<=imgcount; i++) { 
				if(i == 1) { 
					$('#gallery-images-'+tab).append('<li class="active"><img src="/projects/gallery/'+tab+'_'+section+'_pic'+i+'lg.jpg" alt="" /></li>');
				} else {
					$('#gallery-images-'+tab).append('<li><img src="/projects/gallery/'+tab+'_'+section+'_pic'+i+'lg.jpg" alt="" /></li>');
				}
			}
			initAbout(tab, section);
			initGallery(tab);
			$('#waiting_ajax_dialog').jqmHide();
			return false;					   
		});
	});
}

function clearSectionHighlights(tab) {
	$('.section-nav').each(function() {
		$(this).html('<img src="/projects/site-images/'+tab+'_'+$(this).attr("rel")+'_off.png" alt="" border="0" />');
	});
}

function initAbout(tab, section) { 
	$('#about-'+tab).load('/projects/about/'+tab+'_'+section+'.html');
}