var vid_cnt=0;
var navigation_yn='Y';
var vid_src_array=new Array();
var vid_caption_array=new Array();
var wd;

function test() {
   alert('test!');
}

function addvideo(vid_src,vid_caption) {
   vid_cnt = vid_cnt + 1;
   vid_src_array[vid_cnt]=vid_src;

   if (typeof(vid_caption) == 'undefined') {
      vid_caption_array[vid_cnt]='';
   }
   else {
      vid_caption_array[vid_cnt]=vid_caption;
   }
}

function popupYouTubeVideowindow(vid_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";
//   wd=window.open("","",o,true);
//   wd.name="TWCSSlideshow";

   if(wd){
      wd=window.open("","FPYouTubeVids",o,true);
      pw=wd;
   }
   else{
      wd=window.open("","",o,true);
      wd.name="FPYouTubeVids";
   }

   wd.document.open();

   window_str = '<html><head><title>'+vid_caption_array[vid_index]+'</title>';
   window_str+= '<link rel="stylesheet" href="fp_style.css" type="text/css">';
   window_str+= '<script>var cur=' + vid_index +  ';</script>';
   window_str+= '</head>';
   window_str+='<body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>';

   window_str+='<center>'
   window_str+='<div id="videoDiv"></div>'
   window_str+='</body></html>';

   wd.document.writeln(window_str);
   wd.document.close();

   showYouTubeVideo(vid_index);
}

function showYouTubeVideo(vid_index) {

   var div_str;
   var next_video;
   var prev_video;
   var new_title;

   var bigimg;
   var videoDiv = wd.document.getElementById('videoDiv'); 
   var aDiv = wd.document.getElementById('aDiv'); 

   if (!videoDiv)  return;

   if (vid_index == 1) {
     prev_video = vid_cnt;
   }
   else {
     prev_video = vid_index - 1;
   }

   if (vid_index == vid_cnt) {
     next_video = 1;
   }
   else {
     next_video = vid_index + 1;
   }



   videoDiv.innerHTML = 'Loading video...';


      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.popupYouTubeVideowindow(' + prev_video + ')"><img src="images/prev.gif" border=0 alt="Previous Video"></a>';
         div_str+= '        <a href="javascript:window.opener.popupYouTubeVideowindow(' + next_video + ')"><img src="images/next.gif" border=0 alt="Next Video"></a>';
         div_str+='      </td>'
         div_str+='   </tr>'
      }

      div_str+='   <tr height="350">'
      div_str+='      <td class="videoDivVideo" align="center"><object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/' + vid_src_array[vid_index] + '&autoplay=1"></param><embed src="http://www.youtube.com/v/' + vid_src_array[vid_index] + '&autoplay=1" type="application/x-shockwave-flash" width="600" height="350"></embed></object></td>'
      div_str+='   </tr>'

      if (vid_caption_array[vid_index] != '') {
         div_str+='   <tr>'
         div_str+='      <td class="imageDivCaption" align="center">'
         div_str+= '        ' + vid_caption_array[vid_index];
         div_str+='      </td>'
         div_str+='   </tr>'
      }

      div_str+='</table>'

      videoDiv.innerHTML = div_str;
      videoDiv = wd.document.getElementById('videoDiv'); 

      
      wd.resizeTo(videoDiv.clientWidth + 10 ,videoDiv.clientHeight + 70);

      oldTitle = vid_caption_array[vid_index];
      newTitle = oldTitle.replace("<br>"," ");

      while (oldTitle != newTitle) {
         oldTitle = newTitle;
         newTitle = oldTitle.replace("<br>"," ");
      }

      wd.document.title = newTitle;
      wd.focus();


}