var img_cnt=0;
var navigation_yn='Y';
var img_src_array=new Array();
var img_caption_array=new Array();
var img_long_description_array=new Array();
var wd;

function test() {
   alert('test!');
}

function addImage(img_src,img_caption,img_long_description) {
   img_cnt = img_cnt + 1;
   img_src_array[img_cnt]=img_src;

   if (typeof(img_caption) == 'undefined') {
      img_caption_array[img_cnt]='';
   }
   else {
      img_caption_array[img_cnt]=img_caption;
   }
   
   if (typeof(img_long_description) == 'undefined') {
      img_long_description_array[img_cnt]='';
   }
   else {
      img_long_description_array[img_cnt]=img_long_description;
   }
   
   
}

function popupwindow(image_index,nav) {
   var o;
   var window_str;

   if (typeof(nav) != 'undefined') {
      navigation_yn = nav;
   }


   o="toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=1,width=0,height=0";


   if(wd){
      wd=window.open("","TWCSSlideshow",o,true);
      pw=wd;
   }
   else{
      wd=window.open("","",o,true);
      wd.name="TWCSSlideshow";
   }

   wd.document.open();

   window_str = '<html><head><title>'+img_caption_array[image_index]+'</title>';
   window_str+= '<link rel="stylesheet" href="winkys_style.css" type="text/css">';
   window_str+= '<script>var cur=' + image_index +  ';</script>';
   window_str+= '</head>';
   window_str+='<body id="imagePopupBody" leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>';


   window_str+='<center>'
   window_str+='<div id="imageDiv">'
   window_str+='</div>';
   window_str+='</body></html>';

   bigimg=new Image();
   bigimg.src=img_src_array[image_index]

   wd.document.writeln(window_str);
   wd.document.close();

   showImage(image_index);

}

function showImage(image_index) {

   var div_str;
   var next_image;
   var prev_image;

   var bigimg;
   var imageDiv = wd.document.getElementById('imageDiv'); 

   if (!imageDiv)  return;

   if (image_index == 1) {
     prev_image = img_cnt;
   }
   else {
     prev_image = image_index - 1;
   }

   if (image_index == img_cnt) {
     next_image = 1;
   }
   else {
     next_image = image_index + 1;
   }

   imageDiv.innerHTML = 'Loading Image...';

   bigimg=new Image();
   bigimg.onload=function(evt){

      div_str ='<table border=0 border=0 cellspacing=0 cellpadding=0>'

      if (navigation_yn == 'Y') {
         div_str+='   <tr>'
         div_str+='      <td align="left">'
         div_str+= '        <a href="javascript:window.opener.showImage(' + prev_image + ')"><img src="images/prev.gif" border=0 alt="Previous photo"></a>';
         div_str+= '        <a href="javascript:window.opener.showImage(' + next_image + ')"><img src="images/next.gif" border=0 alt="Next photo"></a>';
         div_str+='      </td>'
         div_str+='   </tr>'
      }

      div_str+='   <tr>'
      div_str+='      <td class="imageDivPic" align="center"><img src="' + img_src_array[image_index] + '"></td>'
      div_str+='   </tr>'

      if (img_caption_array[image_index] != '') {
         div_str+='   <tr>'
         div_str+='      <td class="imageDivCaption" align="center">'
         div_str+= '        ' + img_caption_array[image_index];
         div_str+= '       <br>' + img_long_description_array[image_index];
         div_str+='      </td>'
         div_str+='   </tr>'
      }

      div_str+='</table>'

      imageDiv.innerHTML = div_str;

      setTimeout(function() { 
         wd.resizeTo(imageDiv.clientWidth + 10 ,imageDiv.clientHeight + 70);
         wd.document.title = img_caption_array[image_index];
         wd.focus();
      }, 100);


   } 

   bigimg.src=img_src_array[image_index];

}