function flash_detection(required, max)
{
    var required_version = required;
    var max_version = max;
    var available_version = 0;

    if(typeof(navigator.plugins["Shockwave Flash"]) == "object") {
        var description = navigator.plugins["Shockwave Flash"].description;
        available_version = description.substr(16, (description.indexOf(".", 16) - 16));
    } else if(typeof(ActiveXObject) == "function") {
        for(var i = 2; i < (max_version + 1); i ++) {
            try {
                if(typeof(new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i)) == "object") {
                    available_version = i;
                }
           }
           catch(error)
           {
           }
        }
    }

    return [available_version, required_version];
}

function writeFlash(flash, fwidth, fheight, imgdata) {
	var flashver = flash_detection(6, 9);

	if (flashver[0] >= 6) {	

		document.write(
				'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + fwidth + '" height="' + fheight + '">' +
         			'<param name="movie" value="' + flash + '" />' +
         			'<param name="quality" value="high" />' +
		 					'<param name="wmode" value="transparent" />' +
     	    		'<embed src="' + flash + '" quality="high" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + fwidth + '" height="' + fheight + '"></embed>' +
  			'</object>'
		);
	} else {
		document.write(imgdata);
	}
}
