(function($){

	var config = {
		perPage: 16
	};

	$(window).load(function(){

		// setup pager.
		$('#pager').pagination(
			$('#thumbnails li').length,
			{
				callback: function(index) {
					var start = index * config.perPage;
					var end = start + config.perPage;
					$('#thumbnails li')
						// hide all.
						.hide()
						// slice items to show.
						.slice(start, end).fadeIn()
					;
					return false;
				},
				items_per_page: config.perPage,
				prev_text: ' ',//'\u524D\u3078',
				next_text: ' '//'\u6B21\u3078'
			}
		);

		// setup lightbox (colorbox).
		$('#thumbnails a').colorbox(
				{
					slideshow: true,
					slideshowAuto: false,
					slideshowStart: '\u30B9\u30E9\u30A4\u30C9\u30B7\u30E7\u30FC\u3092\u898B\u308B',
					slideshowStop: '\u30B9\u30E9\u30A4\u30C9\u30B7\u30E7\u30FC\u3092\u3084\u3081\u308B',
					opacity: 0.7
				},
				function() {
					// append extra text.
					var text = '<span style="font-size:116%;">';
					text+=$('#intext').text();
					text+='</span><br />';
					text+=$(this).children('img').attr('alt');
					
					$('#cboxTitle').empty();
					$('#cboxTitle').append(text);
					
					// hide position text.
					$('#cboxCurrent').hide();
				}
			)
		;

		// "start slideshow" handler.
		$('#main div.lead p.slideshow a').click(function(){
			var target = $('#thumbnails li:visible a:first');

			// store & extend colorbox options.
			var defaults = $(target).data('colorbox');
			var extended = $.extend({}, defaults, { slideshowAuto: true });

			$(target)
				.data('colorbox', extended)
				.trigger('click.colorbox')
				// restore.
				.data('colorbox', defaults)
			;
			return false;
		});

	});

})(jQuery);

