//////////////////////////////////////////////////////////////////////////////////////////////
//                                   DetectFlash.js                                         //
//////////////////////////////////////////////////////////////////////////////////////////////

/*
  The "detect flash" javascript file enables you to interchange random flash movies/ or images if the user
  doesn't have the flash plugin.
  
  1.  To use this javascript file the global variable "theRoot_Path" must be defined in the "edit.js" file.
      example --> take the url for your site: http://ncdot.org/environment/3R/  and define "theRoot_Path" as
	  theRoot_Path = "/environment/3R/";
  
  2.  Next place the below code anywhere you need the flash/image to appear in your HTML document:
      
      for a single flash animation or image use this:
      <script type="text/javascript" language="javascript">checkFlash(WIDTH, HEIGHT,'graphics/flash/someFLASH1.swf',
	  'graphics/someIMAGE1.gif');</script>
      
	  
      for multiple flash animations or images use this (you can have as many flash animations and images as you want, 
	  just keep adding to the end):
      <script type="text/javascript" language="javascript">checkFlash(WIDTH, HEIGHT,'graphics/flash/someFLASH1.swf',
	  'graphics/someIMAGE1.gif', 'graphics/flash/someFLASH2.swf','graphics/someIMAGE2.gif', 'graphics/flash/someFLASH3.swf',
	  'graphics/someIMAGE3.gif');</script>

*/

//-----------------------------------------------------------------------------------------//

var actualVersion = 0;          // version the user has
var requiredVersion = 4;        // version we planned for, feel free to change 
var maxVersion = 7;             // highest version currently detectable, i'm sure that'll change =)
	
var flash2Installed = false;    // true if flash 2 installed
var flash3Installed = false;    // true if flash 3 installed
var flash4Installed = false;    // true if flash 4 installed
var flash5Installed = false;    // true if flash 5 installed
var flash6Installed = false;    // true if flash 6 installed
var flash7Installed = false;    // true if flash 7 installed

//-----------------------------------------------------------------------------------------//

  function detectFlash(){
    if (navigator.plugins){
      if (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]){

        var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
        var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
        var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
        
        flash2Installed = flashVersion == 2;    
        flash3Installed = flashVersion == 3;
        flash4Installed = flashVersion == 4;
        flash5Installed = flashVersion == 5;
        flash6Installed = flashVersion == 6;
        flash7Installed = flashVersion >= 7;

      }
    }

    for (var i=2; i<=maxVersion; i++) {if(eval("flash" + i + "Installed")==true)actualVersion = i;}

    if(navigator.userAgent.indexOf("WebTV")!=-1)actualVersion = 3;  

    if (actualVersion >= requiredVersion){return true;
	  }else{return false;}
  }

//-----------------------------------------------------------------------------------------//
  
  
  function rotateFlashImages(picWidth, picHeight){

    var hasRightVersion = detectFlash();
    var rotate;
    var increment = 0;
    
    imageRotate = new Array();
    imageRotate = rotateFlashImages.arguments[2].split(",");;
	
    rotate = Math.floor(Math.random()*imageRotate.length);
    
    //alert(imageRotate[rotate]);
    
    if(hasRightVersion){
      var flashImage = '<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'
                     + 'WIDTH="'+picWidth+'" HEIGHT="'+picHeight+'"'
                     + 'CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
                     + '<PARAM NAME="MOVIE" VALUE="'+imageRotate[rotate]+'">'
                     + '<PARAM NAME="PLAY" VALUE="true">'
                     + '<PARAM NAME="LOOP" VALUE="false">'
                     + '<PARAM NAME="QUALITY" VALUE="high">'
                     + '<PARAM NAME="MENU" VALUE="false">'
                     + '<EMBED SRC="'+imageRotate[rotate]+'"'
                     + 'WIDTH="'+picWidth+'" HEIGHT="'+picHeight+'"' 
                     + 'PLAY="true"'
                     + 'LOOP="false"'
                     + 'QUALITY="high"'
                     + 'MENU="false"'
                     + 'TYPE="application/x-shockwave-flash"'
                     + 'PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED></OBJECT>';
        
    }else{
      var flashImage = '<IMG SRC="'+imageRotate[rotate]+'" HEIGHT="'+picHeight+'" WIDTH="'+picWidth+'" ALT="A Random Image">';
    } 
    document.write(flashImage);
  }

  
//-----------------------------------------------------------------------------------------//

  function checkFlash(picWidth, picHeight){
    
    var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false; 
	  var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false; 
	  
	  if(isIE && isWin){
  	  document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
  	  document.write('on error resume next \n');
  	  document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
  	  document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
  	  document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
  	  document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');  
  	  document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');
  	  document.write('flash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');
  	  document.write('</SCR' + 'IPT\> \n');
	  }
    
    var hasRightVersion = detectFlash();
    
    var imageRotate = new Array();
    var increment = 0;
    
    if(hasRightVersion){
      for(var i=2; i<checkFlash.arguments.length; i++){if(i%2==0)imageRotate[increment++] = checkFlash.arguments[i];}
    }else{
      for(var i=2; i<checkFlash.arguments.length; i++){if(i%2==1)imageRotate[increment++] = checkFlash.arguments[i];}
    }
    
    rotateFlashImages(picWidth,picHeight,imageRotate.join());
	  
  }

//-----------------------------------------------------------------------------------------//
