
    function prev_next () {
         /* identify current image*/
         $current_image = document.getElementById("main_image");
         $prev_item = document.getElementById("prev_image");
         $next_item = document.getElementById("next_image");
	
	$linklist = document.getElementsByTagName("a");
        for(i=0;i < $thumblist.length;++i){
            if($current_image.src == $thumblist[i].href) {
              if(i > 0) {
                $prev_item.href = $thumblist[i - 1].href;
                $prev_item.onclick = $thumblist[i - 1].onclick;
              }
              else {
                 $prev_item.href = $thumblist[$thumblist.length - 1].href;
                 $prev_item.onclick = $thumblist[$thumblist.length - 1].onclick;
              }
              if(i == ($thumblist.length - 1)){
                $next_item.href = $thumblist[0].href;
                $next_item.onclick = $thumblist[0].onclick;                
              }
              else {
                $next_item.href = $thumblist[i + 1].href;
                $next_item.onclick = $thumblist[i + 1].onclick;
              }
            }
          }

    }


    function showImage (src,creditline,caption) {
        document.getElementById('main_image').src=src;
        document.getElementById('creditline').innerHTML=creditline;
        document.getElementById('caption').innerHTML=caption;
        prev_next();
    }
    
    $(document).ready(function(){
        $thumblist = new Array();
	$linklist = document.getElementsByTagName("a");
        for(i=0;i < $linklist.length;++i){
          if($linklist[i].className == "img_thumb_link") {
             $thumblist.push($linklist[i]);
          }
        }
      prev_next();
    });
