

var seconds_per_slide = 2.5;
var viewer_picture_size = 512;

window.onload = init;

var buttons = new Array();
function init() {
	setPageContentMinHeight();
	sv = document.getElementById("photo_display-frame");
	sv.appendChild(document.createElement("img")).id = "photo_view";
	pv = document.getElementById("photo_view");
	photo_links = document.getElementById("thumbnails").getElementsByTagName("a");
	for( var i = 0; i < photo_links.length; i++ ) { photo_links[i].onclick = function () { showSlide(this.href); return false; } }
	pv_size = viewer_picture_size;
//	sv.height = pv_size;
	path_to_pic = photo_links[0].href.slice(0, photo_links[0].href.length-10)+pv_size+"/";
//	alert (path_to_pic);
	pv.src=photo_links[0].href;
	var play_pause_links = new Array ( 
		document.getElementById("play").getElementsByTagName("a")[0],
		document.getElementById("pause").getElementsByTagName("a")[0] );
	buttons['play'] = document.getElementById("play").getElementsByTagName("a")[0];
	buttons['pause'] = document.getElementById("pause").getElementsByTagName("a")[0];
	buttons['play'].style.display = "none";
	playShow();
}

function setPageContentMinHeight() {
	var pageContentHeight = document.getElementById('page_content').offsetHeight;
	var otherContentHeight = document.getElementById('site_header').offsetHeight; // + document.getElementById('site-navigation-footer').offsetHeight;
	var contentHeight = pageContentHeight + otherContentHeight;
	document.getElementById('page_content').style.minHeight = getWindowHeight() - otherContentHeight - 18 + 'px';
	}
function getWindowHeight() {
	var windowHeight = 0;
	if ( typeof ( window.innerHeight ) == 'number' ) { windowHeight = window.innerHeight; } 
	else { if ( document.documentElement && document.documentElement.clientHeight ) { 
		windowHeight = document.documentElement.clientHeight; } 
		else { if (document.body && document.body.clientHeight) { windowHeight = document.body.clientHeight; } }
		}
	return windowHeight;
	}

var my_play;
function playShow() { my_play = window.setInterval( "showSlideNum( 'next' );", seconds_per_slide * 1000 ); }


function showSlideNum(choice){
	a=pv.src.length;
	pic_num = pv.src.slice(a-6, a-4)*1;
	if ( choice == "next" ) { pic_num++ }
	if ( choice == "previous"){pic_num-- }
	if ( choice == "first" ) { pic_num = 0 }
	if ( choice == "last" ) { pic_num = photo_links.length - 1 }
	if( pic_num < 0 ) { pic_num = photo_links.length - 1 }
	if( pic_num < 10 ) { pic_num = "0" + pic_num }
	if( pic_num == photo_links.length ) { pic_num = "00" }
	pic_ext = pv.src.slice( a - 4, a );
	pv.src = path_to_pic + pic_num + pic_ext;
	}


function showSlide(referer){
	pause();
//	pic_name = referer.slice(referer.length-6, referer.length);
//	pv.src=path_to_pic+pic_name;
	pv.src = referer;
}


function first() { pause(); showSlideNum("first") }
function previous() { pause(); showSlideNum("previous") }
//function pause() { swapPlayPause("pause"); clearInterval( my_play ); }
function pause() { hide( buttons['pause'] ); display( buttons['play'], '' ); clearInterval( my_play ); }
function play() { hide( buttons['play'] ); display( buttons['pause'], '' ); playShow() }
function next() { pause(); showSlideNum("next") }
function last() { pause(); showSlideNum("last") }

var something, property;
function display ( something, property ) { !property ? 'auto' : property; something.style.display = property; }
function hide ( something ) { something.style.display = 'none'; }

function swapPlayPause( selected_control ){ 
	var s, h;
	if ( selected_control == "pause" ) { s = 1; h = 0; }
	if ( selected_control == "play" ) { s = 0; h = 1; }
	play_pause_links[h].style.display = "none";
	play_pause_links[s].style.display = "inline";
	}
