var currentPhoto = '01';
	
$(document).ready(function() {
	$("#nav a, #subnav a, a.teaser, #projectNav a, #photoNav a").hover(
				// over
				function(){
					// store the original image src
					$(this).children(":first-child").attr( "originalsrc" , $(this).children(":first-child").attr("src") );
					
					// add -over to the image unless it is already -over
					if (!$(this).children(":first-child").attr("src").match(/-over/) ) {
						$(this).children(":first-child").attr( "src", $(this).children(":first-child").attr("src").replace(/\./, "-over.") );
					}
					
				},
				
				// out
				function(){
					// replace the original src
					$(this).children(":first-child").attr(
						"src", $(this).children(":first-child").attr("originalsrc")
					);
					
					$(this).children(":first-child").attr(
						"originalsrc", null
					);
				}
			);
	
	$('a[@rel*=lightbox]').lightBox({
		imageLoading: '/images/lightbox-ico-loading.gif',
		imageBtnClose: '/images/lightbox-btn-close.gif',
		imageBtnPrev: '/images/lightbox-btn-prev.gif',
		imageBtnNext: '/images/lightbox-btn-next.gif',
		imageBlank  : '/images/lightbox-blank.gif'
	});
	
	// project photo numbers
	$('#numbers a').click(function(){
		var photo = $(this).attr('href');
		showPhoto(photo);
		
		// finish up setting hightlight for mouseover
		if (!$('#n' + photo).children(":first-child").attr("originalsrc").match(/-over/) ) {
			$('#n' + photo).children(":first-child").attr( "originalsrc", $('#n' + photo).children(":first-child").attr("originalsrc").replace(/\./, "-over.") );
		}
		
		return false;
	});
	
	
	// project next
	$('a#next').click(function(){
		var nextPhoto = (currentPhoto * 1) + 1;
		if (nextPhoto < 10) {
		   nextPhoto = "0" + nextPhoto;
   		}
		
		// start over if past the last one
		if($('#n' + nextPhoto).length == 0 ) {
			nextPhoto = '01';
		}
		showPhoto(nextPhoto);
		
		return false;
		
	});
	
	// project next
	$('a#back').click(function(){
		var backPhoto = (currentPhoto * 1) - 1;

		// go to the end if before the first
		if (backPhoto == 0) {
			 backPhoto = $('#numbers a:last').attr('href');
		}
		
		if (backPhoto < 10) {
		   backPhoto = "0" + backPhoto;
   		}

		showPhoto(backPhoto);
		
		return false;
		
	});
	
	
});





window.onload = function() {
		// preload
		$("#nav a img, #subnav a img, a.teaser img, #projectNav a img, #photoNav a img").each(
			function() {
				if (!$(this).attr("src").match(/-over/) ) {
					$("<img>").attr( "src", $(this).attr("src").replace(/\./, "-over.") );
				}
			}
		);
}

function showPhoto(photo) {
		// show image
		$('#mainImage img').attr('src', photo + '.jpg');
		// change enlarge link
		$('#mainImage').attr('href', 'large/' + photo + '.jpg');

		currentPhoto = photo;
	
		// reset over state
		$("#numbers a img").each(function() {
				$(this).attr("src", 
					$(this).attr("src").replace(/-over\./, ".") 
				);
			});
		

		// set highlighted
		$('#n' + photo).children(":first-child").attr( "src", $('#n' + photo).children(":first-child").attr("src").replace(/\./, "-over.") );
}