var curthumb = 0;
var numthumbs;
var image1;
var maxthumbs = 40;
var curshowing = 0; // this will go up 1 every time you click "show more"

function showMore() {
	curshowing++;
	$('#thumbs a').slice(maxthumbs,maxthumbs*curshowing).show();
	$('#thumbs a').slice(0,maxthumbs*curshowing).lightBox({overlayOpacity: 0.7, containerResizeSpeed: 250});
	if (maxthumbs*curshowing>numthumbs) {
		$('#thumbs #appendbutton').hide();
	}
}

$(document).ready(function(){
	numthumbs = $('#thumbs img').size(); // calculate number of thumbnails for scrolling and "show more" purposes
	// preload images
	for (i=0;i<=thumbfiles.length;i++) {
		//image1 = $('<img />').attr('src','big/'+thumbfiles[i]);
		//lightbox takes care of this now
	}
	// limit the number of thumbs at first
	$('#thumbs a').slice(maxthumbs,10000).hide();
	showMore();
	if (maxthumbs*curshowing<numthumbs) {
		$('#thumbs #appendbutton').show();
	}
	// add click events on menu links
	$('#links a[href|="#home"]').click(function() {
		$('#links a').css('color','#7A7A7A');
		$(this).css('color','#FFF');
		$('#fotodiv').hide();
		$('#thumbcontainer').hide();
		$('#contactd').hide();
		$('#aboutd').hide();
		$('#homed').fadeIn();
	});
	$('#links a[href|="#designgallery"]').click(function() {
		$('#links a').css('color','#7A7A7A');
		$(this).css('color','#FFF');
		$('#fotodiv').fadeIn();
		$('#thumbcontainer').fadeIn();
		$('#contactd').hide();
		$('#aboutd').hide();
		$('#homed').hide();
	});
	$('#links a[href|="#contact"]').click(function() {
		$('#links a').css('color','#7A7A7A');
		$(this).css('color','#FFF');
		$('#fotodiv').hide();
		$('#thumbcontainer').hide();
		$('#contactd').fadeIn();
		$('#aboutd').hide();
		$('#homed').hide();
	});
	$('#links a[href|="#about"]').click(function() {
		$('#links a').css('color','#7A7A7A');
		$(this).css('color','#FFF');
		$('#fotodiv').hide();
		$('#thumbcontainer').hide();
		$('#contactd').hide();
		$('#aboutd').fadeIn();
		$('#homed').hide();
	});
/*	// add hover class on thumbs
	$('.thumb').hover(
	function() {
		$(this).addClass('thumbhover');
		$(this).removeClass('thumb');
	},
	function() {
		$(this).removeClass('thumbhover');
		$(this).addClass('thumb');
	});
*/
	// fade in foto (if foto page is visible)
	$('#foto').hide();
	$('#extra').hide();
	$('#fotodiv').click(function() {
		$('#foto').fadeOut('fast');
		$('#extra').fadeOut('fast');
	});
	//$('#foto').fadeIn();
	// add click on thumbs for enlargement
	$('.thumb').click(function() {
		return;
		$('#foto').hide();
		$('#foto').attr('src',$(this).attr('src').replace('thumbs/','big/'));
		$('#foto').fadeIn('fast');
		$('#extra').fadeIn('fast');
	});
	// make scrollable thumb bar a fitting size
	// $('#thumbs').css('width',(numthumbs*53)-1+'px');

	// for direct url access using hashes
	if (window.location.hash) {
		$('#links a[href|="'+window.location.hash+'"]').trigger('click');
	} else {
		$('#homed').fadeIn();
	}
	$(window).hashchange(function(){
		$('#links a[href|="'+window.location.hash+'"]').trigger('click');
	});
});

var startscroll = false;
var startdscroll = false;
var scrollspeed = 100; // ms
// scroll up
function prevcat() {
	if (!startscroll) return;
	$('#thumbs').scrollTo('-=50px',scrollspeed,{axis:'y', easing: 'linear'});
	setTimeout("prevcat();",scrollspeed);
}

// scroll down
function nextcat() {
	if (!startdscroll) return;
	$('#thumbs').scrollTo('+=50px',scrollspeed,{axis:'y', easing: 'linear'});
	setTimeout("nextcat();",scrollspeed);
}
