var detectableWithVB = false;
var pluginFound = false;
function redirectCheck(pluginFound, redirectURL, redirectIfFound)
{
 if( redirectURL && ((pluginFound && redirectIfFound) || (!pluginFound && !redirectIfFound)) )
 {
  goURL(redirectURL);
  return pluginFound;
 }
 else
 {
  return pluginFound;
 }	
}
function canDetectPlugins()
{
 if( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0) )
 {
  return true;
 }
 else
 {
  return false;
 }
}
function detectDirector(redirectURL, redirectIfFound)
{
 pluginFound = detectPlugin('Shockwave','Director'); 
 if(!pluginFound && detectableWithVB)
 {
  pluginFound = detectActiveXControl('SWCtl.SWCtl.1');
 }
 return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}
function detectFlash(redirectURL, redirectIfFound)
{
 pluginFound = detectPlugin('Shockwave','Flash'); 
 if(!pluginFound && detectableWithVB)
 {
  pluginFound = detectActiveXControl('ShockwaveFlash.ShockwaveFlash.1');
 }
 return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}
function detectQuickTime(redirectURL, redirectIfFound)
{
 pluginFound = detectPlugin('QuickTime');
 if(!pluginFound && detectableWithVB)
 {
  pluginFound = detectQuickTimeActiveXControl();
 }
 return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}
function detectReal(redirectURL, redirectIfFound)
{
 pluginFound = detectPlugin('RealPlayer');
 if(!pluginFound && detectableWithVB)
 {
  pluginFound = (detectActiveXControl('rmocx.RealPlayer G2 Control') || detectActiveXControl('RealPlayer.RealPlayer(tm) ActiveX Control (32-bit)') || detectActiveXControl('RealVideo.RealVideo(tm) ActiveX Control (32-bit)'));
 }	
 return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}
function detectWindowsMedia(redirectURL, redirectIfFound)
{
 pluginFound = detectPlugin('Windows Media Player');
 if(!pluginFound && detectableWithVB)
 {
  pluginFound = detectActiveXControl('MediaPlayer.MediaPlayer.1');
 }
 return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}
function detectPlugin()
{
 var daPlugins = detectPlugin.arguments;
 var pluginFound = false;
 if (navigator.plugins && navigator.plugins.length > 0)
 {
  var pluginsArrayLength = navigator.plugins.length;
  for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ )
  {
   var numFound = 0;
   for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++)
   {
    if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) )
    {
     numFound++;
    }   
   }
   if(numFound == daPlugins.length)
   {
    pluginFound = true;
    break;
   }
  }
 }
 return pluginFound;
}
function ShowVideo(dir,V_video,tot_video)
{
 newwindow2=window.open('','Main','');
 var tmp = newwindow2.document;
 tmp.writeln('<html>');
 tmp.writeln('<head>');
 tmp.writeln('<title>Video '+V_video+'</title>');
 tmp.writeln('<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">');
 tmp.writeln('<link rel="stylesheet" href="scripts/style.css" type="text/css">');
 tmp.writeln('<script type="text/javascript" src="scripts/Plugin.js"></script>');
 tmp.writeln('</head>');
 tmp.writeln('<body background="images/back.gif">');
 tmp.writeln('<center>');
 number='0000'+V_video;
 filename='video/'+dir+'/video_'+number.substr(number.length-4,4);
 tmp.writeln('<script language="JavaScript" type="text/javascript">{');
 tmp.writeln('document.write(\'<OBJECT CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab" WIDTH="240" HEIGHT="196" SCALE="ASPECT">\');');
 tmp.writeln('document.write(\'<PARAM NAME="src" VALUE="'+filename+'.mov">\');');
 tmp.writeln('document.write(\'<PARAM NAME="autoplay" VALUE="true">\');');
 tmp.writeln('document.write(\'<EMBED SRC="'+filename+'.mov">\');');
 tmp.writeln('document.write(\'HEIGHT="196" WIDTH="240" SCALE="ASPECT"\');');
 tmp.writeln('document.write(\'TYPE="video/quicktime"\');');
 tmp.writeln('document.write(\'PLUGINSPAGE="http://www.apple.com/quicktime/download/"\');');
 tmp.writeln('document.write(\'AUTOPLAY="true"\');');
 tmp.writeln('document.write(\'/>\');');
 tmp.writeln('document.write(\'</OBJECT>\');}');
 tmp.writeln('</script>');
 tmp.writeln('<table width="100%">');
 tmp.writeln(' <tr>');
 if (V_video==1)
 {
  tmp.writeln('  <td width="50%" align="left"><img src="images/previous_greyed.gif" border=0></td>');
 }
 else
 {
  tmp.writeln('  <td width="50%" align="left"><a href="javascript:ShowVideo(\''+dir+'\','+(V_video-1)+','+tot_video+');" onmouseover="window.status=\'\';return true"><img src="images/previous.gif" border=0></a></td>');
 }
 if (V_video==tot_video)
 {
  tmp.writeln('  <td width="50%" align="right"><img src="images/next_greyed.gif" border=0></td>');
 }
 else
 {
  tmp.writeln('  <td width="50%" align="right"><a href="javascript:ShowVideo(\''+dir+'\','+(V_video+1)+','+tot_video+');" onmouseover="window.status=\'\';return true"><img src="images/next.gif" border=0></a></td>');
 }
 tmp.writeln(' </tr>');
 tmp.writeln('</table>');
 tmp.writeln('</center>');
 tmp.writeln('</body>');
 tmp.writeln('</html>');
 tmp.close();
}
if ((navigator.userAgent.indexOf('MSIE') != -1) && (navigator.userAgent.indexOf('Win') != -1))
{
 document.writeln('<script language="VBscript">');
 document.writeln('\'do a one-time test for a version of VBScript that can handle this code');
 document.writeln('detectableWithVB = False');
 document.writeln('If ScriptEngineMajorVersion >= 2 then');
 document.writeln('  detectableWithVB = True');
 document.writeln('End If');
 document.writeln('\'this next function will detect most plugins');
 document.writeln('Function detectActiveXControl(activeXControlName)');
 document.writeln('  on error resume next');
 document.writeln('  detectActiveXControl = False');
 document.writeln('  If detectableWithVB Then');
 document.writeln('     detectActiveXControl = IsObject(CreateObject(activeXControlName))');
 document.writeln('  End If');
 document.writeln('End Function');
 document.writeln('\'and the following function handles QuickTime');
 document.writeln('Function detectQuickTimeActiveXControl()');
 document.writeln('  on error resume next');
 document.writeln('  detectQuickTimeActiveXControl = False');
 document.writeln('  If detectableWithVB Then');
 document.writeln('    detectQuickTimeActiveXControl = False');
 document.writeln('    hasQuickTimeChecker = false');
 document.writeln('    Set hasQuickTimeChecker = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1")');
 document.writeln('    If IsObject(hasQuickTimeChecker) Then');
 document.writeln('      If hasQuickTimeChecker.IsQuickTimeAvailable(0) Then ');
 document.writeln('        detectQuickTimeActiveXControl = True');
 document.writeln('      End If');
 document.writeln('    End If');
 document.writeln('  End If');
 document.writeln('End Function');
 document.writeln('</scr' + 'ipt>');
}
