/* flash player detection object / dhellwig / doku in our wiki */

var checkFlash = {

  _cacheCheckState: "x",
  
  // flash6Installed: false,
  flash6Installed: function()
  {
    if ( this._cacheCheckState != "x" )
    {
        return this._cacheCheckState;
    } else
    {
      if(navigator.plugins && navigator.plugins.length)
      {
        for ( var i=0; i < navigator.plugins.length; i++) {
          var pluginIdent = navigator.plugins[i].description.split(" ");
          if(pluginIdent[0] == "Shockwave" && pluginIdent[1] == "Flash") {
            var versionArray = pluginIdent[2].split(".");
            if(versionArray[0] >= 6) {
               this._cacheCheckState = true;
               return true;
            } else
            {
              this._cacheCheckState = false;
              return false;
            }
            //need to break this loop as some browsers may have two versions installed
            break;
          }//end if pluginIdent
        }//end for
      // MSIE START
      } else if (window.ActiveXObject) {
        try {
          oFlash = eval("new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');");
          if(oFlash) {
            this._cacheCheckState = true;
            return true;
          }
        }
        catch(e) { 
          this._cacheCheckState = false;
          return false;
        }
      }
    }
  },
  
  check: function(flashTeaser, defaultImg, imgLink, linkText, fWidth, fHeight, flashParam, cssClass, cssID)
  { 
    if (checkFlash.flash6Installed()) {
    	if ( fWidth == "" || fHeight == "" )
      {
        return false;
      } else if ( flashTeaser == "" && defaultImg != "" )
      {
        checkFlash.addImage(defaultImg, imgLink, linkText, fWidth, fHeight);
        return true;
      }
      checkFlash.addFlash(flashTeaser, fWidth, fHeight, flashParam, cssClass, cssID);
      return true;
    }
    else if (defaultImg != "") {
      checkFlash.addImage(defaultImg, imgLink, linkText, fWidth, fHeight);
      return true;
    } else {
      return false;
    }
  },
  
  addFlash: function(flashTeaser, fWidth, fHeight, flashParam, cssClass, cssID)
  {
    if ( cssClass != "" )
    {
      cssClass = 'class="' + cssClass + '" ';
    } else
    {
      cssClass = "";
    }
    if ( cssID != "" )
    {
      cssID = 'id="' + cssID + '" ';
    } else
    {
      cssID = "";
    }

    document.write("<object " + cssClass + cssID + " data=\"" + flashTeaser + "\" type=\"application/x-shockwave-flash\" width=\"" + fWidth + "\" height=\"" + fHeight + "\"><param name=\"movie\" value=\"" + flashTeaser + "\" /><param name=\"menue\" value=\"false\" />");
    if ( flashParam != "" ) {
      var flParams = flashParam.split("|");
      for (var j = 0; j < flParams.length; j++) {
        if ( flParams[j].indexOf("=") != -1 ) {
          // do not use flParams[j].split("=") because the string after "=" could contain several "="!
          // example: flParams[j] -> "FlashVars=file=/storage/bla/blub/crazyfrog.mp3&webapp=jamster.com"
          // there are two "=" after 'FlashVars=', the String after 'FlashVars=' have to be a complete string
          var flPar1 = flParams[j].substring(0, flParams[j].indexOf("="));
          var flPar2 = flParams[j].substring(flParams[j].indexOf("=")+1, flParams[j].length);
          if ( flPar2 != "" ) {
            // auf ' pruefen
            document.write('<param name="' + flPar1 + '" value="' + flPar2 + '" />');
          }
        }
      }
    }
    document.write("</object>");
  },
  
  addImage: function( defaultImg, imgLink, linkText, fWidth, fHeight)
  {
    if ( imgLink != "" ) {
      document.write('<a href="' + imgLink + '"><img src="' + defaultImg + '" width="' + fWidth + '" height="' + fHeight + '" alt="' + linkText  + '" /></a>');
    } else {
      document.write('<img src="' + defaultImg + '" width="' + fWidth + '" height="' + fHeight + '" alt="" />');
    }
  }

};
