
javascriptVersion1_1 = true;

// initialize global variables
var detectableWithVB = false;
var pluginFound = false;


function goURL(daURL) {
    // if the browser can do it, use replace to preserve back button
    if(javascriptVersion1_1) {
        window.location.replace(daURL);
    } else {
        window.location = daURL;
    }
    return;
}

function redirectCheck(pluginFound, redirectURL, redirectIfFound) {
    // check for redirection
    if( redirectURL && ((pluginFound && redirectIfFound) ||
        (!pluginFound && !redirectIfFound)) ) {
        // go away
        goURL(redirectURL);
        return pluginFound;
    } else {
        // stay here and return result of plugin detection
        return pluginFound;
    }
}

function canDetectPlugins() {
    if( detectableWithVB || (navigator.plugins && navigator.plugins.length > 0) ) {
        return true;
    } else {
        return false;
    }
}

function detectFlash(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Shockwave','Flash');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
        pluginFound = detectActiveXControl('ShockwaveFlash.ShockwaveFlash.1');
    }
    // check for redirection
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectDirector(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('Shockwave','Director');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
        pluginFound = detectActiveXControl('SWCtl.SWCtl.1');
    }
    // check for redirection
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectQuickTime(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('QuickTime');
    // if not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
        pluginFound = detectQuickTimeActiveXControl();
    }
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectReal(redirectURL, redirectIfFound) {
    pluginFound = detectPlugin('RealPlayer');
    // if not found, try to detect with VisualBasic
    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 not found, try to detect with VisualBasic
    if(!pluginFound && detectableWithVB) {
        pluginFound = detectActiveXControl('MediaPlayer.MediaPlayer.1');
    }
    return redirectCheck(pluginFound, redirectURL, redirectIfFound);
}

function detectPlugin() {
    // allow for multiple checks in a single pass
    var daPlugins = detectPlugin.arguments;
    // consider pluginFound to be false until proven true
    var pluginFound = false;
    // if plugins array is there and not fake
    if (navigator.plugins && navigator.plugins.length > 0) {
        var pluginsArrayLength = navigator.plugins.length;
        // for each plugin...
        for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
            // loop through all desired names and check each against the current plugin name
            var numFound = 0;
            for(namesCounter=0; namesCounter < daPlugins.length; namesCounter++) {
                // if desired plugin name is found in either plugin name or description
                if( (navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) ||
                    (navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
                    // this name was found
                    numFound++;
                }
            }
            // now that we have checked all the required names against this one plugin,
            // if the number we found matches the total number provided then we were successful
            if(numFound == daPlugins.length) {
                pluginFound = true;
                // if we've found the plugin, we can stop looking through at the rest of the plugins
                break;
            }
        }
    }
    return pluginFound;
} // detectPlugin


// Here we write out the VBScript block for MSIE Windows
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>');
}

var gArgCountErr =        'The "%%" function requires an even number of arguments.'
                                +        '\nArguments should be in the form "atttributeName", "attributeValue", ...';

/******************** END LOCALIZABLE **********************/

var gTagAttrs                                = null;
var gQTGeneratorVersion                = 0.8;

function AC_QuickTimeVersion()        { return gQTGeneratorVersion; }

function _QTComplain(callingFcnName, errMsg)
{
    errMsg = errMsg.replace("%%", callingFcnName);
        alert(errMsg);
}

function _QTAddAttribute(prefix, slotName, tagName)
{
        var                value;

        value = gTagAttrs[prefix + slotName];
        if ( null == value )
                value = gTagAttrs[slotName];

        if ( null != value )
        {
                if ( 0 == slotName.indexOf(prefix) && (null == tagName) )
                        tagName = slotName.substring(prefix.length);
                if ( null == tagName )
                        tagName = slotName;
                return tagName + '="' + value + '" ';
        }
        else
                return "";
}

function _QTAddObjectAttr(slotName, tagName)
{
        // don't bother if it is only for the embed tag
        if ( 0 == slotName.indexOf("emb#") )
                return "";

        if ( 0 == slotName.indexOf("obj#") && (null == tagName) )
                tagName = slotName.substring(4);

        return _QTAddAttribute("obj#", slotName, tagName);
}

function _QTAddEmbedAttr(slotName, tagName)
{
        // don't bother if it is only for the object tag
        if ( 0 == slotName.indexOf("obj#") )
                return "";

        if ( 0 == slotName.indexOf("emb#") && (null == tagName) )
                tagName = slotName.substring(4);

        return _QTAddAttribute("emb#", slotName, tagName);
}


function _QTAddObjectParam(slotName, generateXHTML)
{
        var                paramValue;
        var                paramStr = "";
        var                endTagChar = (generateXHTML) ? ' />' : '>';

        if ( -1 == slotName.indexOf("emb#") )
        {
                // look for the OBJECT-only param first. if there is none, look for a generic one
                paramValue = gTagAttrs["obj#" + slotName];
                if ( null == paramValue )
                        paramValue = gTagAttrs[slotName];

                if ( 0 == slotName.indexOf("obj#") )
                        slotName = slotName.substring(4);

                if ( null != paramValue )
                        paramStr = '  <param name="' + slotName + '" value="' + paramValue + '"' + endTagChar + '\n';
        }

        return paramStr;
}

function _QTDeleteTagAttrs()
{
        for ( var ndx = 0; ndx < arguments.length; ndx++ )
        {
                var attrName = arguments[ndx];
                delete gTagAttrs[attrName];
                delete gTagAttrs["emb#" + attrName];
                delete gTagAttrs["obj#" + attrName];
        }
}



// generate an embed and object tag, return as a string
function _QTGenerate(callingFcnName, generateXHTML, args)
{
        // is the number of optional arguments even?
        if ( args.length < 4 || (0 != (args.length % 2)) )
        {
                _QTComplain(callingFcnName, gArgCountErr);
                return "";
        }

        // allocate an array, fill in the required attributes with fixed place params and defaults
        gTagAttrs = new Array();
        gTagAttrs["src"] = args[0];
        gTagAttrs["width"] = args[1];
        gTagAttrs["height"] = args[2];
        gTagAttrs["classid"] = "clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B";
        gTagAttrs["pluginspage"] = "http://www.apple.com/quicktime/download/";

        // set up codebase attribute with specified or default version before parsing args so
        //  anything passed in will override
        var activexVers = args[3]
        if ( (null == activexVers) || ("" == activexVers) )
                activexVers = "6,0,2,0";
        gTagAttrs["codebase"] = "http://www.apple.com/qtactivex/qtplugin.cab#version=" + activexVers;

        var        attrName,
                attrValue;

        // add all of the optional attributes to the array
        for ( var ndx = 4; ndx < args.length; ndx += 2)
        {
                attrName = args[ndx].toLowerCase();
                attrValue = args[ndx + 1];

                // "name" and "id" should have the same value, the former goes in the embed and the later goes in
                //  the object. use one array slot
                if ( "name" == attrName || "id" == attrName )
                        gTagAttrs["name"] = attrValue;

                else
                        gTagAttrs[attrName] = attrValue;
        }

        // init both tags with the required and "special" attributes
        var objTag =  '<object '
                                        + _QTAddObjectAttr("classid")
                                        + _QTAddObjectAttr("width")
                                        + _QTAddObjectAttr("height")
                                        + _QTAddObjectAttr("codebase")
                                        + _QTAddObjectAttr("name", "id")
                                        + _QTAddObjectAttr("tabindex")
                                        + _QTAddObjectAttr("align")
                                        + _QTAddObjectAttr("class")
                                        + _QTAddObjectAttr("title")
                                        + _QTAddObjectAttr("accesskey")
                                        + _QTAddObjectAttr("noexternaldata")
                                        + '>\n'
                                        + _QTAddObjectParam("src", generateXHTML);
        var embedTag = '  <embed '
                                        + _QTAddEmbedAttr("src")
                                        + _QTAddEmbedAttr("width")
                                        + _QTAddEmbedAttr("height")
                                        + _QTAddEmbedAttr("pluginspage")
                                        + _QTAddEmbedAttr("name")
                                        + _QTAddEmbedAttr("align")
                                        + _QTAddEmbedAttr("tabindex");

        // delete the attributes/params we have already added
        _QTDeleteTagAttrs("src","width","height","pluginspage","classid","codebase","name","tabindex",
                                        "align","noexternaldata","class","title","accesskey");

        // and finally, add all of the remaining attributes to the embed and object
        for ( var attrName in gTagAttrs )
        {
                attrValue = gTagAttrs[attrName];
                if ( null != attrValue )
                {
                        embedTag += _QTAddEmbedAttr(attrName);
                        objTag += _QTAddObjectParam(attrName, generateXHTML);
                }
        }

        // end both tags, we're done

        objTag = objTag + embedTag + '> </em' + 'bed>\n<param name="scale" value="tofit"></ob' + 'ject' + '>';
//alert(objTag);
        return objTag;
}

// return the object/embed as a string
function QT_GenerateOBJECTText()
{
        return _QTGenerate("QT_GenerateOBJECTText", false, arguments);
}

function QT_GenerateOBJECTText_XHTML()
{
        return _QTGenerate("QT_GenerateOBJECTText_XHTML", true, arguments);
}

function QT_WriteOBJECT()
{
        document.writeln(_QTGenerate("QT_WriteOBJECT", false, arguments));
}

function QT_WriteOBJECT_XHTML()
{
        document.writeln(_QTGenerate("QT_WriteOBJECT_XHTML", true, arguments));
}

function showFlash(swfFile, pWidth, pHeight)
{
        document.writeln('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+pWidth+'" height="'+pHeight+'" id="flag" align="top">');
        //document.writeln('<param name="allowScriptAccess" value="sameDomain">');
        document.writeln('<param name="movie" value="'+swfFile+'">');
        //document.writeln('<param name="quality" value="high">');
        //document.writeln('<param name="scale" value="noscale">');
        //document.writeln('<param name="salign" value="rt">');
        //document.writeln('<param name="wmode" value="transparent">');

		document.writeln('<embed width="' + pWidth + '" height="' + pHeight + '"');
        document.writeln('        pluginspage="http://www.macromedia.com/go/getflashplayer"');
        document.writeln('        type="application/x-shockwave-flash"');
        document.writeln('        src="' + swfFile + '"');
		document.writeln('        />')


        document.writeln('</object>');
}

function  loadTour(qtFile, swfFile, pWidth, pHeight)
{
        var quickTimeIsInstalled = detectQuickTime();
        var flashIsInstalled = detectFlash();

        if(quickTimeIsInstalled)
        {
                QT_WriteOBJECT_XHTML(qtFile, pWidth, pHeight, '','autoplay', 'false','emb#bgcolor', 'white','align', 'middle');
        }
        else if(flashIsInstalled)
        {
                showFlash(swfFile, pWidth, pHeight);
        }
        else
        {
                alert("You have no QuickTime and Macromedia Flash plug-ins installed in your browser!");
        }
}

