$(document).ready(function () {
	// menus
    $('a#project-link').click(
    	function (event) {
            event.preventDefault();
    		$('div#menu-wrapper').slideToggle('medium');
    	}
    );
    $('div#menu-wrapper').mouseleave( 
    	function () { 
			$('div#menu-wrapper').slideUp('medium');
   		}
    );
	
	
	// detail page thumbs
	$('a#previous-images').hide();
	window.currentThumbSet = 1;
	window.totalThumbSets = 0;
	$('div.thumb-set').each ( function () { window.totalThumbSets++; });
	
	$('.thumb-set a').click (
		function (event) {
			event.preventDefault();
			$('img#detail-image').attr('src', '/img'+$(this).attr('data-detail'));
		}
	);
	
	$('a#previous-images').click (
		function (event) {
			event.preventDefault();
			showPreviousImages();
		}
	);
	
	$('a#next-images').click (
		function (event) {
			event.preventDefault();
			showNextImages();
		}
	);
});

function showPreviousImages () {
	if (window.currentThumbSet > 1) {
		$('#thumb-set-'+window.currentThumbSet).fadeOut(
			'fast',
			function () {
				window.currentThumbSet--;
				$('#thumb-set-'+window.currentThumbSet).fadeIn(
					'fast',
					function () {
						if (window.currentThumbSet <= 1) $('a#previous-images').hide();
						if (window.currentThumbSet < window.totalThumbSets) $('#next-images').show();
					}
				)
			}
		);
	}
}

function showNextImages () {
	if (window.currentThumbSet < window.totalThumbSets) {
		$('#thumb-set-'+window.currentThumbSet).fadeOut(
			'fast', 
			function () {
				window.currentThumbSet++;
				$('#thumb-set-'+window.currentThumbSet).fadeIn(
					'fast',
					function () {
						if (window.currentThumbSet >= window.totalThumbSets) $('a#next-images').hide();
						if (window.currentThumbSet > 1) $('a#previous-images').show();
					}
				)
			}
		);
	}
}
