// Flash & browser detection
function Is() {
    agent       = navigator.userAgent.toLowerCase();

    this.major  = parseInt(navigator.appVersion);
    this.minor  = parseFloat(navigator.appVersion);
    this.ns     = ((agent.indexOf('mozilla') != -1) && ((agent.indexOf('spoofer') == -1) && (agent.indexOf('compatible') == -1)));
    this.ns4    = (this.ns && (this.major == 4));
    this.ns6    = (this.ns && (this.major >= 5));
    this.ns7    = (this.ns && (agent.indexOf('netscape/7')!=-1));
    this.ie     = (agent.indexOf("msie") != -1);
    this.ie3    = (this.ie && (this.major < 4));
    this.ie4    = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.0") == -1));
    this.ie5    = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.0") != -1));
    this.ie55   = (this.ie && (this.major == 4) && (agent.indexOf("msie 5.5") != -1));
    this.ie6    = (this.ie && (agent.indexOf("msie 6.0")!=-1));
    this.cs6    = (agent.indexOf("2000 6")!=-1); // CompuServe 6.0
    this.cs7    = (agent.indexOf("cs 2000 7")!=-1); // CompuServe 7.0
    this.mac    = (agent.indexOf("mac")!=-1); // Mac detect
}
var is = new Is();
// Detect Netscape's plugin version major and minor & VB script to detect IE's plugin version
var detectedFlashVersion = -1;
function getFlashVersion(baseVersion) {
    if (detectedFlashVersion != -1) return detectedFlashVersion;
    if (baseVersion == null) baseVersion = 25;
    if (navigator.plugins != null && navigator.plugins.length > 0) {
        var pluginRef = navigator.plugins["Shockwave Flash"];
        if (pluginRef != null) {
            var flashDescription = pluginRef.description;
            descArray = flashDescription.split(" ");
            tempVerArray = descArray[2].split(".");
            versionMajor = tempVerArray[0];
            if (descArray[3] != "") {
                tempMinorArray = descArray[3].split("r");
            } else {
                tempMinorArray = descArray[4].split("r");
            }
            versionMinor = tempMinorArray[1] > 0 ? tempMinorArray[1] : 0;
            detectedFlashVersion = parseFloat(versionMajor + "." + versionMinor);
        }
    }
    else if ((window.ActiveXObject) && (navigator.userAgent.indexOf("MSIE")!= -1) && (navigator.userAgent.indexOf("Windows") != -1)) {
        document.write('<scr' + 'ipt language="VBScript"\> \nPrivate i, x\nOn Error Resume Next\nMM_FlashControlInstalled = False\nFor i = ' + baseVersion + ' To 1 Step -1\n');
        document.write('Set x = CreateObject("ShockwaveFlash.ShockwaveFlash." & i)\nMM_FlashControlInstalled = IsObject(x)\nIf MM_FlashControlInstalled Then\ndetectedFlashVersion = CStr(i)\nExit For\nEnd If\nNext\n');
        document.write('</scr' + 'ipt\> \n');
    }
    return detectedFlashVersion;
}
// display flash .swf if user has correct browser and flash plugin version or display fail safe graphic
function flashEmbed(movieName, failOverImage, failOverURL, width, height, baseVersion, bgColor) {
    if (detectedFlashVersion >= baseVersion && (is.mac || is.cs7 || is.ns)) bolPlugin = true;
    else if (is.ie && parseInt(navigator.appVersion) >= 4 && (detectedFlashVersion >= baseVersion)) bolPlugin = true;
    else bolPlugin = false;
    if (bolPlugin) {
        writeFlashTag(movieName, width, height, baseVersion, bgColor);
    }else{
    document.write ('<a href = "' + failOverURL + '"><img src = "' + failOverImage + '" width="' + width + '" height="' + height + '" border = "0"></a>');
    return;
  }
}

// display flash .swf if user has correct browser and flash plugin version or display fail safe graphic
function flashEmbedCustomTag(classid, codebase, width, height, src, pluginspage, id, swliveconnect, play, loop, menu, quality, scale, align, salign, wmode, bgcolor, baseVersion, failHTML) {
    if (detectedFlashVersion >= baseVersion && (is.mac || is.cs7 || is.ns)) {
        bolPlugin = true;
    } else if (is.ie && parseInt(navigator.appVersion) >= 4 && (parseInt(detectedFlashVersion) >= parseInt(baseVersion))) {
        bolPlugin = true;
    } else {
        bolPlugin = false;
    }

    if (bolPlugin) {
        writeFlashCustomTag(classid, codebase, width, height, src, pluginspage, id, swliveconnect, play, loop, menu, quality, scale, align, salign, wmode, bgcolor, baseVersion);
    }else{
        document.write (failHTML);
    return;

  }
}

// embed the flash swf
function writeFlashTag(movieName, width, height, baseVersion, bgColor) {
    document.write ('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + baseVersion + ',0,0,0" width="' + width + '" height="' + height + '">\n<param name="movie" value="' + movieName + '">\n<param name="bgcolor" value="' + bgColor + '">\n<param name="quality" value="high">\n<param name="allowScriptAccess" value="always">\n');
    document.write ('<embed src="' + movieName + '" TYPE="application/x-shockwave-flash" quality="high" allowScriptAccess="always" bgcolor="' + bgColor + '" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" width=' + width + ' height=' + height + '></embed>\n</object>');
    return;
}

// embed the flash swf with custom tags
function writeFlashCustomTag(classid, codebase, width, height, src, pluginspage, id, swliveconnect, play, loop, menu, quality, scale, align, salign, wmode, bgcolor, baseVersion) {

    // alert('<object classid="' + classid + '" codebase="' + codebase + baseVersion + ',0,0,0" width="' + width + '" height="' + height + '">\n<param name="movie" value="' + src + '">\n<param name="bgcolor" value="' + bgcolor + '">\n<param name="quality" value="' + quality + '">\n<param name="play" value="' + play + '">' +
    // '<embed src="' + src + '" TYPE="application/x-shockwave-flash" quality="' + quality + '" bgcolor="' + bgcolor + '" pluginspage="' + pluginspage + '" width="' + width + '" height="' + height + '" swliveconnect="' + swliveconnect + '" play="' + play + '"></embed>\n</object>');

    document.write ('<object classid="' + classid + '" codebase="' + codebase + baseVersion + ',0,0,0" width="' + width + '" height="' + height + '">\n<param name="movie" value="' + src + '">\n<param name="bgcolor" value="' + bgcolor + '">\n<param name="quality" value="' + quality + '">\n<param name="allowScriptAccess" value="always">\n');
    document.write ('<embed src="' + src + '" TYPE="application/x-shockwave-flash" allowScriptAccess="always" quality="' + quality + '" bgcolor="' + bgcolor + '" pluginspage="' + pluginspage + '" width="' + width + '" height="' + height + '" swliveconnect="' + swliveconnect + '" play="' + play + '"></embed>\n</object>');

    return;
}

// detects browsers and sends user for flash plugin update
function updateFlash(baseVersion) {
    if (is.ie && !is.mac) {
        iFrame = document.createElement('IFRAME');
        iFrame.frameBorder ='0';
        iFrame.scrolling='no';
        iFrame.width='1';
        document.body.appendChild(iFrame);
        iFrame.src = "/g/i/flash/upgrade.html";
    } else {
        window.location.href="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash";
        return;
    }
}

function refreshFlash() {
    location.reload();
}

// Function to be used to write a generic tag.  This exists because of the pending change to
// the Internet Explorer ActiveX model, which would cause a user to get prompted when launching
// an ActiveX control unless it is written indirectly by an external js file.
function writeGenericTag(tag) {
    document.write(tag)
}