<!--

var clickedLi = null;

function loadSlideURL(slideIndex) {
  var slidePrefix = 'slide=';
  var url = document.URL;
  var slideIndexInURL = url.indexOf(slidePrefix);

  if( slideIndexInURL != -1 ) {
    url = url.substring(0, slideIndexInURL - 1)
        + url.substring(slideIndexInURL + slidePrefix.length + 1);
  }

  url += (url.indexOf('?') != -1 ?'&':'?') + 'slide=' + slideIndex;
  document.location = url;
}

function showThumbImage(slide) {
 // var caption = document.getElementById("caption");
  var rtFrame = document.getElementById("rtFrameImg");
  //var imgBg  = "url(" + slide.imageSrc + ")";

  //rtFrame.style.backgroundImage = imgBg;
   rtFrame.src = slide.imageSrc;
   caption.innerHTML = slide.caption;

  var lis = document.getElementById("thumb_list_box").getElementsByTagName("li");
  for( var i = 0; i<lis.length; i++ ) {
    lis[i].className = "";
  }
  clickedLi.className = "active";
}

function doSlideshowLayout() {
  if( slides.length == 0 ) {
    document.getElementById("thumb_list_box").style.display = "none";
  } else {
    var ul = document.getElementById("thumb_list_box").getElementsByTagName("ul")[0];

    var getSlide = GET('slide');
    getSlide = getSlide != null ? getSlide : 0;
    
    // Because of some weird bug,
    // put the body of the for loop
    // at the end of this function in
    // a closure and call it in the for loop
    var layout = function(slide, slideIndex) {
      var li, img;
      if(slide.thumbSrc == null)
	return;
      li = document.createElement("li");
      img = document.createElement("img");
  
      img.src = slide.thumbSrc;
      img.alt = slide.caption;
         
      //li.onclick = function() { loadSlideURL(slideIndex); } 
      li.onclick = function() { clickedLi = li; showThumbImage(slide); } 

      li.onmouseover = function() { hoverThumb(li, true); }
      li.onmouseout = function() { hoverThumb(li, false); }
  
      li.appendChild(img);
      ul.appendChild(li);

      if( getSlide == slideIndex ) {
        clickedLi = li;
      }	
    }

    for( var i=0; i<slides.length; i++ ) {
      layout(slides[i], i);
    }

    showThumbImage(slides[getSlide]);
  }  
}

function GET( name ) {
  var url = document.URL;
  var indexOfNameA = url.indexOf( '&' + name + '=' );
  var indexOfNameB = url.indexOf( '?' + name + '=' );
  
  var indexOfName = (indexOfNameA != -1) ? indexOfNameA : (indexOfNameB != -1) ? indexOfNameB : -1;

  if( indexOfName == -1 ) return null;

  var nameValue = '';
  var charIndex = indexOfName + name.length + 2;
  while( charIndex < url.length ) {
    var curChar = url.charAt(charIndex++);
    if( curChar != '&' ) nameValue += curChar;
    else break;
  }
  return nameValue;
}

function hoverThumb( li, over ) {
  if( li ) {
    li.className = over ? "active" : (clickedLi == li) ? "active" : "";
  }  
}

function documentDidLoad() {
}

//-->
