/*
 Use this to replace flash on a page for a given jpg
 
*/

//determines whether or not the installed version meets minumum compatability
//  this should be change
var minFlashVersion = 5;  //change this according to requirements

//replace the flash object which is a child of thisId node, with src, height and width of an image
function replaceFlash(thisId, imgSrc, height, width) {
    var img = document.createElement("img");
    img.src = imgSrc;
    img.height = height;
    img.width = width;
    img.border = 0;
    var p = document.getElementById( thisId );
    p.removeChild( p.childNodes[0] );
    p.appendChild( img );    
}


function getFlashVersion() {
   var flashVersion = 0;
   var latestFlashVersion = 8;
   var agent = navigator.userAgent.toLowerCase(); 
   
   // NS3 needs flashVersion to be a local variable
   if (agent.indexOf("mozilla/3") != -1 && agent.indexOf("msie") == -1) {
      flashVersion = 0;
   }
   
   // NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Flash plugin in plugin array
   if (navigator.plugins != null && navigator.plugins.length > 0) {
      var flashPlugin = navigator.plugins['Shockwave Flash'];
      if (typeof flashPlugin == 'object') { 
         for (var i = latestFlashVersion; i >= 3; i--) {
            if (flashPlugin.description.indexOf(i + '.') != -1) {
               flashVersion = i;
               break;
            }
         }
      }
   }

   // 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) {
	for(var i=latestFlashVersion; i>0; i--){
		flashVersion = 0;
		try{
			var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i);
			flashVersion = i;
			break;
		}
		catch(e){
		}
	}
   }
      
   // WebTV 2.5 supports flash 3
   else if (agent.indexOf("webtv/2.5") != -1) flashVersion = 3;

   // older WebTV supports flash 2
   else if (agent.indexOf("webtv") != -1) flashVersion = 2;

   // Can't detect in all other cases
   else {
      flashVersion = -1; //don't know version
   }

   return flashVersion;
}
