<!--

lastOn    = "";
imagesAt  = "./img/";
buttonSrc = "";
saveTrim = "";
galleryPlaying = false;

rotating = new Array("pic01", "pic02", "pic03", "pic04", "pic05", "pic06", "pic07", "pic08", "pic09", "pic10"); 

random.m = 714025; random.a = 4096; random.c=150889;
random.seed = (new Date()).getTime()% random.m;
isOn = new Object();
maxPics = 0;

function findObj(n, d) { 
var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=FindObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function random() {
	random.seed = (random.seed*random.a + random.c) % random.m;
	return random.seed / random.m;
}

function msgOn(imgName, msgName, suffix) {
//	turn on the button image
	retVal = imgOn(imgName);

//	set defaults
 	if (!msgName) { msgName = "blurb"; }
    if (!suffix) { suffix = "gif"; }

//	early out if this isn't a message!
	if (document[msgName] == null) { return false; }

//	clear pending timeouts
    if (document[msgName].timeID) {
    	clearTimeout(document[msgName].timeID);
    	document[msgName].timeID = null;
    }
//	save the original source if it isn't save already
    if (!document[msgName].saveSrc) {
    	document[msgName].saveSrc = document[msgName].src;
    }
    
	lastOn = imgName;
    document[msgName].src = imagesAt + "blurb-" + imgName + "." + suffix;
    return 
}

function msgOff(imgName, msgName) {
	retVal = imgOff(imgName);
	
	if (!imgName) {
		imgName = lastOn;
	}
	if (!msgName) {
		msgName = "blurb";
	}
	if (document[msgName] == null) { return false; }
	cmdStr = 'timedOff("' + msgName + '");';
	document[msgName].timeID = setTimeout(cmdStr, 500);
    return false;
}

function timedOff(srcName) {
	if (!srcName) {
	    srcName = "blurb";
	}
	document[srcName].src = document[srcName].saveSrc;
	document[srcName].timeID = null;
}

function asciiNo(lb, ub) {
    binNo = ((new Date()).getSeconds() % ub) + 1;
    if (binNo > ub) { binNo = lb };
    if (binNo < 10) {
        ascNo = "0" + binNo;
    }
    else {
    	ascNo = binNo;
    }
    return ascNo;
}

function chooseTrim(callRotate) {
	buttonSrc = document["trimColor"].src	// there must be a named image with the correct color...
	preload = new Image();
	preload.src = buttonSrc; // preload the rollover...
	
	if (callRotate == 1) {
		for (i = 1; i<=maxPics; i++) {	// Say that none of the pictures in the gallery are
		   isOn[i] = 0;					// being shown. This keeps two "random" pictures being
		}								// the same...

		startRotate(1, 0, 9, 5371);
	}
}

function galleryShow(picId) {
	galleryStop();
	var id = picId % maxPics;
	document.forms.flipId["currentPic"].value = _source[id];
	document["bigPicture"].src = "./img/photo/" + _source[id] + ".jpg";
	document["bigPicture"].alt = _titles[id];
	document["bigPicture"].title = _titles[id] + "; " + _locals[id];
	findObj("bigTitle").innerHTML = _titles[id];
	findObj("bigLocation").innerHTML = _locals[id];
	_ord = picId - _picId;
	return false;
}

function galleryResetid() {
	var s = new String(document.forms.flipId["currentPic"].value);
	for (i = 0; i < maxPics; i++) {
		if (_source[i] == s.toUpperCase()) {
			return galleryShow(i);
		}
	}
	return galleryShow(0);
	document.forms.flipId["currentPic"].value = '0000';
}

function navMessage(msg) {
	if (document["navBlurb"] == null) { return false; }
	var img = document["navBlurb"];
	if (msg == null) {
		img.src = img.saveSrc;
		return false;
	}
	if (img.saveSrc == null) {
		img.saveSrc = img.src;
	}
	img.src = "./img/" + msg + ".gif";
	return false;
}

function galleryNext() {
	galleryStop();
	_ord = (_ord + 1) % (_rows * _cols);
	if (_ord == 0) {
		return galleryNextPage();
	}
	return galleryShow(_picId + _ord);
}

function galleryPrev() {
	galleryStop();
	if (_ord == 0) {
		_ord = (_rows * _cols) - 1;
		if (_picId <= 0) {
			_picId = maxPics;
		}
		_picId = _picId - (_rows * _cols);
		if (_picId < 0) { _picId = maxPics + _picId; }
		galleryThumbs();
	}
	else {
		_ord--;
	}
	return galleryShow(_picId + _ord);
}

function galleryNextPage() {
	galleryStop();
	_picId = (_picId + (_rows * _cols)) % maxPics;
	galleryThumbs();
	return galleryShow(_picId);
}

function galleryPrevPage() {
	galleryStop();
	if (_picId == 0) {
		_picId = maxPics;
	}
	_picId = _picId - (_rows * _cols);
	if (_picId < 0) {
		_picId = maxPics + _picId;
	}
	galleryThumbs();
	return galleryShow(_picId);
}

function galleryPlay(pp, first) {
	if (galleryPlaying) {
		galleryPlaying = false;
		document["navPlay"].src = "./img/navPlay.jpg";
		return;
	}
	document["navPlay"].src = "./img/navStop.jpg";
	galleryPlaying = true;
	galleryAuto(pp, first);
	return false;
}

function galleryStop() {
	if (galleryPlaying) {
		galleryPlaying = 0;
		document["navPlay"].src = "./img/navPlay.jpg";
	}
	return false;
}

function galleryAuto(pp, first) {
	if (galleryPlaying) {
		_ord = pp;
		var id = (_picId + pp) % maxPics;
		document.forms.flipId["currentPic"].value = _source[id];
		document["bigPicture"].src = "./img/photo/" + _source[id] + ".jpg";
		document["bigPicture"].alt = _titles[id];
		document["bigPicture"].title = _titles[id] + "; " + _locals[id];
		findObj("bigTitle").innerHTML = _titles[id];
		findObj("bigLocation").innerHTML = _locals[id];
		if (((pp % (_cols * _rows)) == 0) && (first != 1)) {
			_picId = (_picId + (_rows * _cols)) % maxPics;
			galleryThumbs();
			pp = 0;
		}
		pp++;
		_timeId = setTimeout("galleryAuto(" + pp + ", 0)", 4721);
	}
}

function galleryThumbs() {
	var picId = _picId;
	for (var i=0; i < _rows; i++) {
		for (var j=0; j < _cols; j++) {
			var picName = "_gallery_" + i + "_" + j;
			document[picName].src = "./img/photo/tn/" + _source[picId++] + ".jpg";
			picId = picId % maxPics;
		}
	}
}

function galleryGoto(picName, trim) {
	if (trim == null) { trim = ""; }
	window.location = "./photo.php?_t=" + trim + "&_id=" + _source[document[picName].currentIdx];
	return false;
}

function imgOn(imgName) {
	if (document[imgName] == null) { return false;}
	if (!document[imgName].saveSrc) {
		document[imgName].saveSrc = document[imgName].src;
	}
	document[imgName].src = buttonSrc;
	
	lastOn = imgName;
	return false;
}
function imgOff(imgName) {
	if (!imgName) {
		imgName = lastOn;
	}
	
	if (document[imgName] == null) { return false;}
	document[imgName].src = document[imgName].saveSrc;
	return false;
}

function nextImg(imgName, imgType, lb, ub) {
//	alert("nextImg(" + imgName + ", " + imgType + ", " + lb + ", " + ub + ")");
	if (document[imgName] == null) { return true; }
	lb    = Math.abs(lb);
	ub    = Math.abs(ub);

	myIndex = Math.round((random() * ub)) % ub;
	while (isOn[myIndex] == 1) { // if it's on, find the closest empty one
		myIndex++;
		if (myIndex > ub) { myIndex = 1; }
	}
	
	isOn[myIndex] = 1; // Say this one is on...
	if (document[imgName].currentIdx != null) {
		isOn[document[imgName].currentIdx] = 0;
	}
	
	newSrc = imagesAt + "photo/tn/" + _source[myIndex] + "." + imgType;

//	alert("newSrc='" + newSrc + "'");
	
	document[imgName].src = newSrc;
	document[imgName].currentIdx = myIndex; // remember the index that is on

	return true;
}

function startRotate(first, lb, ub, delay) {
    first = Math.abs(first);
	lb    = Math.abs(lb);
	ub    = Math.abs(ub);
	delay = Math.abs(delay);
	
	if (first == 1) { // need to initially load them all
	    for (i = lb; i <= ub; i++) {
	         nextImg(rotating[i], 'jpg', 1, maxPics);
	    }
	}
	else { // otherwise, choose a random one to rotate
		flipped = new Array();
		for (i = lb; i <= ub; i++) { flipped[i] = 0; }
		
		flip   = Math.round((random() * ub)) % ub;
		nextImg(rotating[flip], 'jpg', 1, maxPics);
		flipped[flip] = 1; // we flipped this element already
		
		flip   = Math.round((random() * ub)) % ub;
		while (flipped[flip] == 1) {
			flip++;
			if (flip > ub) { flip = lb; }
		}
		nextImg(rotating[flip], 'jpg', 1, maxPics);
		flipped[flip] = 1; // we flipped this element already

	}
	
//	alert("startRotate(" + first + ", " + lb + ", " + ub + ", " + delay + "), absIdx='" + absIdx + "'");

	nextCommand = "startRotate(0, " + lb + ", " + ub + ", " + delay + ");";
	timeID = setTimeout(nextCommand, delay);
 	return true;
}

function say(car, cdr, text) {
    var a = new Array('o', 't', 'l', 'i', 'a', 'm');
    a.reverse(); car.reverse(); cdr.reverse();
    var a_joined = a.join('');
    var j = car.join('') + '&' + '#6' + '4;' + cdr.join('.');
    if ((text == null) || (text == '')) { text = j }
    document.write('<a href="' + a_joined + ':' + j + '">' + text + '</a>');
    return true;
}

// -->
