// ===========================================================================
// FILENAME: flasher.js
//  PURPOSE: Collection of utility methods useful in detecting Shockwave Flash
//           plugins, so we know whether or not to rely on Flash content.  It
//           is based loosely on FlashSwapper by Isaac Schlueter.
//  CREATED: 20-FEB-2007 by Evan Atkinson 
// ===========================================================================

// Determines the version of Shockwave Flash that is installed as a plugin for
// the browser.  Returns -1 if cannot determin and 0 if plugin found but its
// version cannot be determined.  Successful calls return the version number.
// NOTE: Flash plugin descriptions are *usually* like Shockwave Flash 7.0 r19.
// This method might need to just pull the first number and hope for the best.
function FlashVer() {
    var sFlashDesc = '';
    if (navigator) {
        if (navigator.appVersion) {
            if (navigator.appVersion.indexOf("MSIE") != -1 &&
                navigator.appVersion.toLowerCase().indexOf("win") != -1) {
                if (MSIE_FlashVersion_Installed == -1) {
                    MSIE_FlashVersion_DetectVB();
                }
                return MSIE_FlashVersion_Installed;
            }
        }
        if (navigator.mimeTypes) {
            var oMime = navigator.mimeTypes['application/x-shockwave-flash'];
            if (oMime && oMime.enabledPlugin) {
                if (oMime.enabledPlugin.description) {
                    sFlashDesc = oMime.enabledPlugin.description;
                } else {
                    return 0;
                }
            }
        } else if (navigator.plugins) {
            var oPlugSW  = navigator.plugins['Shockwave Flash'];
            var oPlugSW2 = navigator.plugins['Shockwave Flash 2.0'];
            if (oPlugSW) {
                sFlashDesc = oPlugSW.description;
            } else if (oPlugSW2) {
                sFlashDesc = oPlugSW2.description;
            }
        }
        if (sFlashDesc != '') {
            var v = parseInt(sFlashDesc.replace(/^[^0-9]*/,''));
            if (!isNaN(v)) {
                return v;
            }
        }
    }
    return -1;
}

// Determines version of Flash plugin for MSIE platforms using VB script.
// Do not invoke this function on non-MSIE platforms ... no good there.
function MSIE_FlashVersion_DetectVB() {
    document.write('<script language="VBScript" type="text/VBScript"> \n');
    document.write('on error resume next\n');
    document.write('dim i,f\n');
    document.write('i = MSIE_FlashVersion_MAXVERNUM\n');
    document.write('Do While i >= 2 \n');
    document.write('    Set f = CreateObject(');
    document.write('        "ShockwaveFlash.ShockwaveFlash." & i)\n');
    document.write('    If Err.Number = 0 Then\n');
    document.write('        MSIE_FlashVersion_Installed = i\n');
    document.write('        Set f = Nothing\n');
    document.write('        Exit Do\n');
    document.write('    Else\n');
    document.write('        Err.Clear\n');
    document.write('    End If\n');
    document.write('    Set f = Nothing\n');
    document.write('    i = i - 1\n');
    document.write('Loop\n');
    document.write('<\/script> \n');
}

// Max version of flash to ever deal with, affects VB script above.  Setting
// too high gives bad performance, too low yields poor detection.
var MSIE_FlashVersion_MAXVERNUM = 20;

// Version of flash installed, as detected by the VB script above.  This var
// is set as necessary when calling the FlashVer function under MSIE.
var MSIE_FlashVersion_Installed = -1;

//============================================================================
