

var iw = 1200;
var INTERVAL = 5;
var data_tags = new Array();
var current = 0;
var autoID = "";

try {
	x = location.search;
	if (x.length > 1) {
		x = parseInt(x.substr(1));
		if ((x > 2) && (x < 600) ) {
			INTERVAL = x;
			alert("slides show interval changed to " + INTERVAL + " seconds");
		}
		else {
			alert("invalid or not a number " + x);
		}
	}
}
catch (e) {
	alert("invalid or not a number " + x);
}

function start() {
	divs = document.getElementsByTagName('div');
	for (i = 0; i < divs.length; i++) {
		if (divs[i].className == 'record') {
			data_tags[current] = divs[i];
			current++;
		}
		else {
		}
	}
	if ((data_tags.length == current) && (data_tags.length > 1) ) {
		document.getElementById('interval').innerHTML = INTERVAL;
		document.getElementById('page_contents').style.display = 'none';
		document.getElementById('waiting').style.display = 'inline';
		document.getElementById('info').style.display = 'none';
		adjust();
		document.getElementById('waiting').style.display = 'none';
		document.getElementById('info').style.display = 'inline';
		document.getElementById('page_contents').style.display = 'block';
	}
	else {
		alert("unexpected error");
	}
}

function showSlide(idx) {
	var pop = null;
	var slide = null;
	var newImg = null;
	pop = document.getElementById('popup');
        pop.style.display = 'none'; // hack for IE 5.5, should not too harmful with any browser 
	curData = data_tags[idx];
curPath = "/photos/" + curData.id.substring(0, 6) + "/";

	if (navigator.userAgent.indexOf ('MSIE 5') > 1) {
  		document.getElementById('slide').src = curPath + curData.id + ".jpg"; // did not work properly in IE 6.0
	}
	// worked with IE 6.0 and Firefox
	else {
  		slide = document.getElementById('slide');
  		newImg = document.createElement("img");
  		newImg.setAttribute("src", curPath + curData.id + ".jpg");
  		newImg.setAttribute('align', 'left');
  		newImg.setAttribute('border',  2);
  		newImg.setAttribute('hspace',  2);
  		// newImg.setAttribute('style',  'position:absolute;left:18em;top:0px;'); /// XXX cf left setting ! wo
  		newImg.setAttribute('id', 'slide');
  		slide.parentNode.replaceChild(newImg, slide);
  		newImg.style.position = 'absolute';
  		newImg.style.left='18em';
  		newImg.style.top ='0px';
	}
	n = idx + 1;
	document.getElementById('current').innerHTML = "[" + n + "]";
	document.getElementById('caption').innerHTML = curData.innerHTML;
	if (window.innerWidth) {
		iw = window.innerWidth;
	}
	else {
		iw = document.body.clientWidth;
	}
	iw = iw -4;
	pop.style.width=iw + 'px';
	pop.style.display = 'block';
	document.getElementById('main').style.display = 'none';
	window.scrollTo(0,0);
}				

function showEnlarged(oImg) {
	splitted = oImg.src.split('/');
	idValue = splitted[splitted.length - 1].split('.')[0];
	var j = -1;
	for (i = 0; i < data_tags.length; i++) {
		if (idValue == data_tags[i].id) {
			j = i;
			break;
		}
	}
	if (j != -1) {
		current = j;
		showCurrent();
	}
	else {
		alert("unexpected error, nothing to do");
	}
}

function showNext() {
	current++;
	showCurrent();
}

function showPrevious() {
	current--;
	if (current < 0) {
	   current = data_tags.length - 1;
	}
	showSlide(current);
}

function showCurrent() {
	if (current == data_tags.length) {
		current = 0;
	}
	showSlide(current);
}

function hideSlide() {
	document.getElementById('popup').style.display = 'none';
	document.getElementById('main').style.display = 'block';
	if (autoID) {
		stop();
	}
}

function auto() {
	document.getElementById('auto_stop').style.display = 'inline';
	document.getElementById('auto_start').style.display = 'none';
	showNext();
	autoID = setInterval("showNext()", INTERVAL * 1000);
}

function stop() {
	document.getElementById('auto_stop').style.display = 'none';
	document.getElementById('auto_start').style.display = 'inline';
	clearInterval(autoID);
	autoID = 0;
}

// not in use anymore
w = null;
function enlarge(o) {
	if ((w != null) && (! w.closed)) {
		w.close();
	}
	w = window.open(o.src);
	w.focus();
}


// XXXXX for now use images[] more than one
/// and table.className = "thums"
function adjust() {
	maxWidth = screen.width;
	// perhaps monitors with 1100* don't exist, but ..
	if (maxWidth < 1100) {
		// perhaps getElementsByTagName is better than document.images
		// XXX: temp: assuming that ALL images are slides // XXXXX for now use images[] more than one
		// XXX: adjusting only for 1024 px, without calculations in place
		slides = document.getElementsByTagName('img');
		for (i = 1; i < slides.length; i++) {
			if (slides[i].className != 'symbMap') {
				slides[i].style.height = "200px";
			}
		}
		tables = document.getElementsByTagName('table');
		for (i = 0; i < tables.length; i++) {
		  if (tables[i].className = "thums") {
				tables[i].width = 960; // 950 worked, too
			}
		}
	}
	else {
		maxw=960;
		tables = document.getElementsByTagName('table');
		for (i = 0; i < tables.length; i++) {
			if (tables[i].clientWidth > maxw) {
				maxw = tables[i].clientWidth;
				
			}
		}
		/*
		for (i = 0; i < tables.length; i++) {
			if (tables[i].className = "thums") {
				tables[i].width = maxw; // XXXXX
				alert('adjusting to ' + maxw);
			}
		}*/
	}	
	if (maxWidth < 1000) {
		alert("This page is best viewed with screen resolution higher than 1024 px horizontally.\n" +
		"Cannot adjust settings for curent resolution (" + maxWidth + " by " + screen.height + " px)");
	}
	
}
			

