/**
 * Generates sequential IDs.
 */
var IdFactory = {

    nextId: 1,
    
    getId: function ()
    {
        return this.next++;
    }
}

/**
 * Helper function used by embedFlash().
 */
function getWidthHeightAttrs(w, h)
{
    var s = "";
    if (w > 0)
        s += ' width="' + w + '"';
    if (h > 0)
        s += ' height="' + h + '"';
    return s;
}

/**
 * Embeds a Flash animation on the page. If Flash is not supported by
 * the user agent, the image at "altImgPath" is shown instead. Most of
 * this code was generated by Macromedia Flash 6.
 */
function embedFlash( swfPath, altImgPath, width, height, doc )
{
    doc = doc || document;
    var reqVersion = 4;
    var canPlay = false;
    
    var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"])
        ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0;
    if ( plugin ) {
        var words = navigator.plugins["Shockwave Flash"].description.split(" ");
        for (var i = 0; i < words.length; ++i) {
            if (isNaN(parseInt(words[i])))
                continue;
            var pluginVersion = words[i]; 
        }
        canPlay = pluginVersion >= reqVersion;
    }
    else if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 
       && (navigator.appVersion.indexOf("Win") != -1))
    {
        try {
            var flashObj = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + reqVersion);
            canPlay = true;
        } catch (e) {}
    }
    if ( canPlay ) {
        var flashId = "flashObject" + IdFactory.getId();
        doc.write('<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
//        doc.write('  codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" ');
        doc.write(' ID="' + flashId + '"' + getWidthHeightAttrs(width, height) + '" ALIGN="left">');
        doc.write(' <PARAM NAME=movie VALUE="' + swfPath + '"> <PARAM NAME=quality VALUE=best> <PARAM NAME=salign VALUE=LT> <PARAM NAME=bgcolor VALUE=#FFFFFF>  '); 
        doc.write(' <EMBED src="' + swfPath + '" quality=best salign=LT bgcolor=#FFFFFF  ');
        doc.write(' swLiveConnect=FALSE WIDTH="' + width + '" HEIGHT="' + height + '" NAME="' + flashId + '" ALIGN="left"');
        doc.write(' TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/go/getflashplayer">');
        doc.write(' </EMBED>');
        doc.write(' </OBJECT>');
    } else{
        doc.write('<IMG SRC="' + altImgPath + '"' + getWidthHeightAttrs(width, height) + '" BORDER="0">');
    }
}

