// Flash detection script
// Checks for Flash 2 - 10
// Tested:
// PC: Mozilla 1.6, Netscape 7.02, MS IE 5.0/5.5/6.0, Firefox 1.0 PR, Opera 7.52
// Mac: MS IE 5.2, Firefox 0.9.1, safari 1.2.3

// Script requires two variabels set in the page before this script is loaded:
/*
  // Set required Flash version here
  var minimumFlashVersion=7;
  // Set url for invalid flash version redirection
  var redirectUrl='http://www.rijksmuseum.nl/getflash';
*/

var flashInstalled = 0;
var flashVersion = 0;
var MSDetect = "false";

if (navigator.plugins && navigator.plugins.length) {
  x = navigator.plugins["Shockwave Flash"];
  if (x) {
    flashInstalled = 2;
    if (x.description){
        y = x.description;
        // Split description on spaces.
        y_chunks = y.split(" ");
        // Loop through all chunks and take first chunk that contains a number. 
        // This should be the rounded version number right away:
        // y_chunks[0] contains "Shockwave"
        // y_chunks[1] contains "Flash"
        // y_chunks[2] contains version: /^\d+\.?\d?/ (e.g.: "10.0" or "9.0")
        // y_chunks[3] contains release: /^r\d+\.?\d?/ (e.g.: "r12" or "r11.3.5");
        for (i = 0; i < y_chunks.length; i++) {
            if (parseInt(y_chunks[i]) > 0) {
                flashVersion = parseInt(y_chunks[i]);
                continue; // Stop if we have an integer match!
            }
        }
    }
  } else {
    flashInstalled = 1;
  }
  if(navigator.plugins["Shockwave Flash 2.0"]){
    flashInstalled = 2;
    flashVersion = 2;
  }
} else if (navigator.mimeTypes && navigator.mimeTypes.length) {
  x = navigator.mimeTypes['application/x-shockwave-flash'];
  if(x && x.enabledPlugin){
    flashInstalled = 2;
  } else {
      flashInstalled = 1;
  }
} else {
    // Any other browsers
    // This doesn't work for Netscape 2, Konqueror and Explorer 3 and 4 on Mac,
    // since they don't support VBScript.
  MSDetect = "true";
  document.write('<script type="text/vbscript"\> \n');
  document.write('on error resume next \n');
  document.write('If MSDetect = "true" Then \n');
  document.write('  For i = 2 to 12 \n');
  document.write('    If Not(IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & i))) Then \n');
  document.write('    Else \n ');
  document.write('      flashInstalled = 2 \n');
  document.write('      flashVersion = i \n');
  document.write('    End If \n ');
  document.write('   Next \n');
  document.write('End If \n');
  document.write('If flashInstalled = 0 Then \n');
  document.write('   flashInstalled = 1 \n');
  document.write('End If');
  document.write('</script\> \n');
}

if ((flashInstalled == 2) && (flashVersion >= minimumFlashVersion)) {
  // Flash installed oke
  //  alert('Flash player '+flashVersion+' detected.')
} else {
    window.opener.document.location.href=redirectUrl;
    window.close()
}

