var nowShowingPhoto = 0;
var candidateOnShow = 0;

var candidates = new Array(
	'',
	'文柏姿',
	'倫紫玄',
	'張舒雅',
	'高海寧',
	'梁倩汶',
	'陳倩揚',
	'梁雅琳',
	'姚婷芝',
	'謝靜婷',
	'史宛殷',
	'馬賽',
	'黃潔婷'
);

jQuery(
	function(){
		jQuery('.gallery-thumb-tab').show();
		var randomCandidate = Math.ceil( Math.random() * jQuery('#gallery-thumbs a img').length );
		candidateOnShow = randomCandidate;
		showGalleryOf( candidateOnShow );
		
		jQuery('#gallery-thumbs a img').each(
			function(){
				jQuery(this).click(
					function(){						
						showGalleryOf( jQuery('#gallery-thumbs a img').index(this) );
					}
				);
			}
		);

		jQuery('#gallery-prev').click(
			function(){
				showPhoto( nowShowingPhoto - 1 );
			}
		);

		jQuery('#gallery-next').click(
			function(){
				showPhoto( nowShowingPhoto + 1 );
			}
		);
	}
);

function showPhoto(i) {
	nowShowingPhoto = i
	jQuery('#gallery-of-' + candidateOnShow + ' img').hide();
	jQuery('#gallery-of-' + candidateOnShow + ' img:eq(' + i + ')').show();
	if (nowShowingPhoto <= 0) {
		jQuery('#gallery-prev').hide();
	} else {
		jQuery('#gallery-prev').show();
	}
	if (nowShowingPhoto >= jQuery('#gallery-of-' + candidateOnShow + ' img').length - 1) {
		jQuery('#gallery-next').hide();
	} else {
		jQuery('#gallery-next').show();
	}
	jQuery('#nowshowing').html('第' + ( i + 1 ) + '張，共' + jQuery('#gallery-of-' + candidateOnShow + ' img').length + '張');
}

function showGalleryOf (j) {
	candidateOnShow = j;
	jQuery('#gallery > div').hide();
	jQuery('#gallery-of-' + candidateOnShow).show();
	jQuery('#gallery-of').html( j + '. ' + candidates[j] )
	showPhoto(0);
}