$(document).ready(function(){
	$('#icons a').click(function(e){
		e.preventDefault();
		var photoid = $(this).attr('photoid');
		$('#photo').attr('src','/photo/900/'+pad(photoid,4)+'.jpeg');
		$('#photo').attr('photoid',photoid);
		//.css('margin',0).width('auto').height('auto');
		//FitPage();
	});
	$('#photo,#prevnext').mouseover(function(e){
        $('#prevnext').show();
	});
	$('#prevnext').mouseout(function(e){
		$('#prevnext').hide();
	});
	$('#arrow-left').live('click',function(e){
		e.preventDefault();
		var bigphotoid = $('#photo').attr('photoid');
		var photoid = $('#icons [photoid='+bigphotoid+']').prev().attr('photoid');
		if (photoid == undefined) photoid = $('#icons a').last().attr('photoid');
		$(this).blur();
		$('#photo').attr('photoid',photoid);
		$('#photo').attr('src','/photo/900/'+pad(photoid,4)+'.jpeg');
	});
	$('#arrow-right').live('click',function(e){
		e.preventDefault();
		var bigphotoid = $('#photo').attr('photoid');
		var photoid = $('#icons [photoid='+bigphotoid+']').next().attr('photoid');
		if (photoid == undefined) photoid = $('#icons a').first().attr('photoid');
		$(this).blur();
		$('#photo').attr('photoid',photoid);
		$('#photo').attr('src','/photo/900/'+pad(photoid,4)+'.jpeg');
	});
	$('#icons a').mouseover(function(e){
		var photoid = $(this).attr('photoid');
		$('#icon').html('<img src="/photo/50x50/'+pad(photoid,4)+'.jpeg" />');
		$('#icon').css('top',  $(this).offset().top-60);
        $('#icon').css('left', $(this).offset().left-14);
        $('#icon').show();
	});
	$('#icons a').mouseout(function(e){
		$('#icon').hide();
	});

	//FitPage();
	//$(window).bind('resize', function(){	//	FitPage();	//});});

function FitPage() {	var maxwidth = 900;
	$('#main').height(window.innerHeight-30);
	var img_w = $('#photo img').width();
	var img_h = $('#photo img').height();
	var img_h_new = window.innerHeight-160;
	var dh = img_h/img_h_new;
	var img_w_new = img_w/dh;
	if (img_w_new < maxwidth) {
		$('#photo img').width('auto');
		$('#photo img').height(img_h_new);
		$('#photo img').css('margin',0);	} else {
		$('#photo img').width(maxwidth);
		$('#photo img').height('auto');
		var margin = (img_h_new-$('#photo img').height()) / 2;
		if (margin > 0) {$('#photo img').css('margin-top',margin).css('margin-bottom',margin);}	}}

function pad(number, length) {
    var str = '' + number;
    while (str.length < length) {
        str = '0' + str;
    }
    return str;
}
