/**
 *
 */

var photo_table = [];
var photo_table_count = 0;

var photo_next_fin = true;
function
photo_next()
{
	photo_next_fin = false;

	var photo_number = photo_table[ photo_table_count ];
	var n = ("00" + photo_number);
	var img = "photo_" + n.substr( n.length - 3 ) + ".jpg";
	var img_obj;
	var h,w;
	var o;

	o = $('#photo_outer #thumb1');

	w = 186;
	h = 139;
	$('#photo_outer').height( h );
	$('#photo_outer').width(  w );
	img_obj = new Image();
	img_obj.onload = function () {
		o.fadeOut( 2000, function () {
			o.html('');
			o.html('<img src="' + img_obj.src + '" width=' + img_obj.width + " height=" + img_obj.height + '>');
			$('#photo_inner').css( 'padding-top',  (h - img_obj.height) / 1 ).css( 'padding-left', (w - img_obj.width)  / 2 );
			o.hide();
			$( '#thumb1' ).attr( 'href', "photos/fin/" + img );
			o.fadeIn( 6000, function () {
				make_sub_image();
				photo_table_count = (photo_table_count + 1) % photo_table.length;
				photo_next_fin = true;
			} );
		} );
	};
	img_obj.src = "photos/dst/" + img;
}


function
make_sub_image()
{
	var i;
	var img;
	var html = '';

	for( i = 0; i < photo_max; i++ ) {
		if( i == photo_table_count ) {
			continue;
		}
		var n = ("00" + photo_table[i]);
		img = "photo_" + n.substr( n.length-3 ) + ".jpg";
		html += '<a href="photos/fin/' + img + '" class="highslide" onclick="return hs.expand(this, { thumbnailId: \'thumb1\' } )">';
		html += '<img src="photos/dst/' + img + '">';
		html += '</a>';
		html += '<div class="highslide-caption">';
		html += '</div>';
	}
	$('#photo_outer .hidden-container').html( html );
}

function
mini_gallery_init()
{
	var html = '';
	var img;
	var i;

	for( i = 0; i < photo_max; i++ ) {
		photo_table[i] = 0;
	}

	var n;
	var l;
	for( i = photo_max; i > 0 ; i-- ) {
		n = Math.floor( Math.random() * i ); 
		for( l = 0; l < photo_max; l++ ) {
			if( photo_table[l] == 0 ) {
				if( n == 0 ) {
					photo_table[l] = i;
					break;
				}
				n--;
			}
		}
	}

	hs.graphicsDir = 'js/lib/highslide/highslide/graphics/';
	hs.showCredits = false;
	hs.align = 'center';
	hs.transitions = ['expand', 'crossfade'];
	hs.outlineType = 'rounded-white';
	hs.fadeInOut = true;
	hs.numberPosition = 'caption';
	hs.dimmingOpacity = 0.70;

	hs.lang = {
			   cssDirection: 'ltr',
			   loadingText : '読み込み中...',
			   loadingTitle : 'クリックで中断',
			   focusTitle : 'Click to bring to front',
			   fullExpandTitle : '拡大表示 (f)',
			   creditsText : 'Powered by <i>Highslide JS</i>',
			   creditsTitle : 'Go to the Highslide JS homepage',
			   previousText : '前',
			   nextText : '次', 
			   moveText : '移動',
			   closeText : '閉じる', 
			   closeTitle : '閉じる (esc)', 
			   resizeTitle : 'リサイズ',
			   playText : 'スライドショー',
			   playTitle : 'スライドショー (spacebar)',
			   pauseText : '一時停止',
			   pauseTitle : '一時停止 (spacebar)',
			   previousTitle : '前 (arrow left)',
			   nextTitle : '次 (arrow right)',
			   moveTitle : '移動',
			   fullExpandText : '1:1',
			   number: '%2枚中 %1枚目',
			   restoreTitle : 'Click to close image, click and drag to move. Use arrow keys for next and previous.'
	};

//	hs.transitions = [];
	hs.transitions = ['expand', 'crossfade'];
	hs.transitionDuration = 1000; // default 250

	
	hs.marginBottom = hs.getPageSize().pageHeight / 10 * 1.2;
	hs.marginTop = hs.getPageSize().pageHeight / 10 * 1.2;


	hs.expandDuration = 250;  // 最初の表示
	hs.restoreDuration = 250;

	// Add the controlbar
	if (hs.addSlideshow) hs.addSlideshow({
		//slideshowGroup: 'group1',
		interval: 5000,
		repeat: false,
		useControls: true,
		fixedControls: 'fit',
		overlayOptions: {
			opacity: .75,
			position: 'bottom center',
			hideOnMouseOut: true
		},
		thumbstrip: {
			position: 'bottom center',
			mode: 'horizontal',
			relativeTo: 'viewport'
		}
	});
	
}

$(window).load( function() {
	mini_gallery_init();
	photo_next();
	make_sub_image();

//	setInterval( function () {
	setTimeout( function () {
		if( photo_next_fin ) {
			photo_next();
		}
	} , 7000 );		
} );


/*
	<a href="../images/gallery2.jpg" class="highslide" onclick="return hs.expand(this, { thumbnailId: 'thumb1' })"></a>
	<div class="highslide-caption">
		Caption for the second image.
	</div>

	<a href="../images/gallery3.jpg" class="highslide" onclick="return hs.expand(this, { thumbnailId: 'thumb1' })"></a>
	<div class="highslide-caption">
		Caption for the third image.
	</div>
</div>
*/

/**
 *
 */