// Script for display pages
// Copyright (c) 2006, 2007 Mark A. Brown
//
// Requires: xbase.js, netloader.js, lbstore.js, lightbox.js

var selected = 0;	// currently visible image
var scrollSpeed = 2;


function showmain(n) {
	for (var i=0; i<imgid.length; i++) {
		var mi = xGetElementById('pic' + i);
		var mj = xGetElementById('text' + i);
		mi.style.visibility = i==n ? 'visible' : 'hidden';
		mj.style.visibility = 'hidden';
	}
	xGetElementById('picid').innerHTML = 'Image ID: ' + imgid[n];
	xGetElementById('piclabel').innerHTML = imgtext[n];
	selected = n;
	updateLightboxDisplay();
}


function moveUp() {
	xGetElementById('thumbs').scrollTop -= scrollSpeed;
	moveUpMark = setTimeout("moveUp()", scrollSpeed);
}

function moveDown() {
	xGetElementById('thumbs').scrollTop -= -scrollSpeed;
	moveDownMark = setTimeout("moveDown()", scrollSpeed);
}

function scrollUp() {
	xGetElementById('thumbs').scrollTop -= 90;
}

function scrollDown() {
	xGetElementById('thumbs').scrollTop -= -90;
}


function mouseOver(e) {
	var mi = xGetElementById('text' + selected);
	mi.style.visibility = 'visible';
	if (!e)
		var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation)
		e.stopPropagation();
}

function mouseOut(e) {
	var mi = xGetElementById('text' + selected);
	mi.style.visibility = 'hidden';
	if (!e)
		var e = window.event;
	e.cancelBubble = true;
	if (e.stopPropagation)
		e.stopPropagation();
}

function SetEventHandler() {
	for (var i=0; i<imgid.length; i++) {
		var mi = xGetElementById('pic' + i);
		var imgs = xGetElementsByTagName('img', mi);
		imgs[0].onmouseover = mouseOver;
		imgs[0].onmouseout  = mouseOut;
	}
}

function updateLightboxDisplay() {
	if (lightBox.enabled) {
		var selid = imgid[selected];
		var lbadd  = xGetElementById('lbadd');
		var lbview = xGetElementById('lbview');
		if (lightBox.isOnLightBox(selid)) {
			lbadd.style.display = 'none';	
		}
		else {
			lbadd.style.display = 'inline';
		}
		var n = lightBox.numberOfImages();
		var lbf = xGetElementById('lbframe');
		if (lbf) {
			lbf.style.visibility = n ? 'visible' : 'hidden';
		}
	}
}


function lbadd() {
	addtolightbox(imgid[selected]);
}



window.onload=function() {
	SetEventHandler();
	if (lightBox.enabled) {
		loadlightbox(updateLightboxDisplay);
	}
}

window.onunload=function() {
	savelightbox();
}


// End
