function chgPhoto(strAdj)
{
 var myList = document.getElementById("picselect");
 var myImg = document.getElementById("photo");
 switch (strAdj)
 {
  case "+":
   if (myList.selectedIndex < myList.length - 1) {
     if (!myList.hasfocus) myList.selectedIndex = myList.selectedIndex + 1;
     UpdateIMG();
   } else {
     // do nothing!
   }
   break;
  case "-":
   if (myList.selectedIndex > 0) {
     if (!myList.hasfocus) myList.selectedIndex = myList.selectedIndex - 1;
     UpdateIMG();
   } else {
     // do nothing!
   }
   break;
  case "first":
   myList.selectedIndex = 0;
   UpdateIMG();
   break;
  case "last":
   myList.selectedIndex = myList.length - 1;
   UpdateIMG();
   break;
  default:
   UpdateIMG();
 }
}
function UpdateIMG()
{
 var myPath = "";  /* set as desired for site */
 showMsg();
 var myImg = document.getElementById("photo");
 myImg.onload = clearMsg;
 var myList = document.getElementById("picselect");
 // Handle initial page load including possible query argument
 if (myImg.src.indexOf(".jpg") < 0) {
  if (location.search != "") {
   var strTemp = location.search;
   var numTemp = parseInt(strTemp.substr(1, strTemp.length - 1));
   if (numTemp < myList.length - 1) {
     myList.selectedIndex = numTemp;
   }
  }
 } else { // force the toollayer to close
   toggleTools(true);
 }
 myImg.src = myPath + myList.options[myList.selectedIndex].value;
}
function showMsg() { document.getElementById("plswait").innerHTML = "Loading..."; }
function clearMsg() { document.getElementById("plswait").innerHTML = "Ready"; }
function keys(key)
{
 // return if toollayer inputs are being edited
 if ((document.getElementById("HtmlLink").hasfocus) || 
     (document.getElementById("BBLink").hasfocus)) return;
 if (!key) {
  key = event;
  key.which = key.keyCode;
 }
 switch (key.which) {
  case 39: // rightkey
  case 40: // downkey
   chgPhoto('+');  // go to next slide
   break;
  case 37: // leftkey
  case 38: // upkey
   chgPhoto('-');  // go to previous slide
   break;
  case 36: // home
   chgPhoto('first');  // go to first slide
   break;
  case 35: // end
   chgPhoto('last');  // go to last slide
   break;
  case 84: // t -- toggle tool layer
   toggleTools(false);
   break;
 }
 return false;
}
function toggleTools(strOffOnly)
{
 var myBtn = document.getElementById("toolsbtn");
 if ((myBtn.className != "liston") && (!strOffOnly)) { //show tools
  // depress button
  myBtn.className = "liston";
  // build links and fields
  document.getElementById("toolslink1").href = document.getElementById("photo").src;
  document.getElementById("toolslink2").href = document.getElementById("photo").src;
  var myList = document.getElementById("picselect");
  var myUrl = location.href;
  if (myUrl.indexOf("?") > -1) myUrl = myUrl.substr(0,myUrl.indexOf("?")-1);
  myUrl += "?" + myList.selectedIndex.toString();
  var myText = "Thailand Food Photos: " + myList.options[myList.selectedIndex].text;
  document.getElementById("HtmlLink").value = "<a href=\"" + myUrl + "\">" + myText + "</a>";
  document.getElementById("BBLink").value = "[url=\"" + myUrl + "\"]" + myText + "[/url]";
  // make div visible
  document.getElementById("toollayer").style.visibility = "visible";
 } else { // hide tools
  // make div hidden
  document.getElementById("toollayer").style.visibility = "hidden";
  // restore button
  myBtn.className = "";
 }
}
// Following code runs at load time only
if (!document.getElementById){
  alert("Navigation requires a more recent browser such as Internet Explorer 5.5 - 6 or Mozilla Firefox.");
} else {
  document.onkeyup = keys;
  window.onload = function(){UpdateIMG();toggleTools();}
}

