// 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 detectedVersion = -1;
var detectedMVersion = 0;
function getFlashVersion(baseVersion) {
    if (detectedVersion != -1) return detectedVersion;
    if (baseVersion == null) baseVersion = 10;
    if (navigator.plugins != null && navigator.plugins.length > 0) {
        var pluginRef = navigator.plugins["Shockwave Flash"];
        if (pluginRef != null) {
            var verIndex = pluginRef.description.indexOf (".");
            detectedVersion = parseInt (pluginRef.description.substr (verIndex - 1, 1));
            detectedMVersion = pluginRef.description.substr (verIndex + 2);
        }
    }
        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\ndetectedVersion = CStr(i)\nExit For\nEnd If\nNext\n');
            document.write('</scr' + 'ipt\> \n');
    }
    return detectedVersion;
}
// 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 (detectedVersion >= baseVersion && (is.mac || is.cs7 || is.ns)) bolPlugin = true;
    else if (is.ie && parseInt(navigator.appVersion) >= 4 && (detectedVersion >= baseVersion)) bolPlugin = true;

    else bolPlugin = false;
    
    bolPlugin = true;
    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 (detectedVersion >= baseVersion && (is.mac || is.cs7 || is.ns)) {
        bolPlugin = true;
    } else if (is.ie && parseInt(navigator.appVersion) >= 4 && (parseInt(detectedVersion) >= 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');
    document.write ('<embed src="' + movieName + '" TYPE="application/x-shockwave-flash" quality="high" 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');
    document.write ('<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>');

    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();
}