var QTVersion = 0;
QTVersion = getQuicktimeVersion();

function getQuicktimeVersion() {
    if (QTVersion) return QTVersion;

    var agent = navigator.userAgent.toLowerCase();

    // NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Quicktime plugin in plugin array
    if (navigator.plugins != null && navigator.plugins.length > 0) {
      for (i=0; i < navigator.plugins.length; i++ ) {
         var plugin =navigator.plugins[i];
         if (plugin.name.indexOf("QuickTime") > -1) {
            quicktimeVersion = parseFloat(plugin.name.substring(18));
         }
      }
    }

    // IE4+ Win32:  attempt to create an ActiveX object using VBScript
    else if (agent.indexOf("msie") != -1 && parseInt(navigator.appVersion) >= 4 && agent.indexOf("win")!=-1 && agent.indexOf("16bit")==-1) {
        document.write('<scr' + 'ipt language="VBScript"\> \n');
        document.write('on error resume next \n');
        document.write('dim obQuicktime \n');
        document.write('set obQuicktime = CreateObject("QuickTimeCheckObject.QuickTimeCheck.1") \n');
        document.write('if IsObject(obQuicktime) then \n');
        document.write('   if obQuicktime.IsQuickTimeAvailable(0) then \n');
        document.write('      quicktimeVersion = CInt(Hex(obQuicktime.QuickTimeVersion) / 1000000) \n');
        document.write('   end if \n');
        document.write('end if \n');
        document.write('</scr' + 'ipt\> \n');
  }

    // Can't detect in all other cases
    else {
        quicktimeVersion=-1;
    }

    //alert(quicktimeVersion);
    return quicktimeVersion;
}

/**
 * Modified to take advantage of Prototype magic
 */
function embedQuicktime(input_params) {
    /*
        url: url,
        width: width,
        height: height,
        autoplay: autoplay,
        poster_url: poster_url,
        scale: scale,
        insert_into: insert_into,
        insert_after: insert_after,
        alt: alternative_text,
    */
    // default parameters
    params = {
        width:    240,
        height:   180,
        autoplay: false,
        scale:    'aspect',
        padding:  'auto',
        alt: ''
    };

    for (var key in input_params) {
        params[key] = input_params[key];
    }

    // convert params to proper type for inserted html.
    params.autoplay = (params.autoplay)? 'true' : 'false';

    var out = ('<div style="padding:' + params.padding + '">');
    out += ('<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" width="'+params.width+'" height="'+params.height+'" codebase="http://www.apple.com/qtactivex/qtplugin.cab">');
        if (params.poster_url) {
            out += ('<param name="src" value="'+params.poster_url+'" />');
            out += ('<param name="qtnext1" value="'+params.url+' T<myself>" />');
        } else {
            out += ('<param name="src" value="'+params.url+'" />');
        }
        out += ('<param name="autoplay" value="'+params.autoplay+'" />');
        out += ('<param name="controller" value="true" />');
        out += ('<param name="scale" value="' + params.scale + '" />');

        out += ('<embed ');
            if (params.poster_url) {
                out += ('src = "' + params.poster_url + '" ');
                out += ('qtnext1 = "' + params.url + ' T<myself>" ');
            } else {
                out += ('src = "' + params.url + '" ');
            }
            out += ('width="' + params.width + '" height="' + params.height + '" ');
            out += ('autoplay="'+params.autoplay+'" ');
            out += ('controller="true" ');
            out += ('pluginspace="http://www.apple.com/quicktime/download/" ');
            out += ('scale="' + params.scale + '" ');
            out += ('>');
        out += ('</embed>');
        out += ('<noembed>' + params.alt + '</noembed>');

    out += ('</object></div>');

    // only execute the before and after insert if prototype is installed
    if(false && $(params.insert_into)) {
        Element.update(params.insert_into, out);
        if(params.insert_after) {
            new Insertion.Bottom(params.insert_into, params.insert_after);
        }
    } else {
        document.write(out);
    }
}

