/*
*10/11/05
*@author Aono
*Check Flash plugin and ipad,iphone
*Flashの有無とiPhone,iPadのみ判別して動作を分岐
*<example>
    $f_env.switch_if({
        flashEnabled : function(){
            alert( "flashEnable" )
        },
        flashDisabled : function(){
            alert( "flashDisable" )
        },
        appleMobile : function(){
            alert( "appleMobile" )
        }
    })
*</example>
*/

(function( win , _plugins  , agent , env_string ){
   var  hasFlash = (function(){
        
        var iter    =   -1,
            len     =   _plugins.length,
            ff      =   agent.indexOf( "Firefox" ) > -1,
            ie      =   agent.indexOf( "MSIE" ) > -1,
            safari  =   agent.indexOf( "Safari" ) > -1,
            tp;
        
        //For webkit and gecko    
        if( ff || safari ){
          
          while( ( tp = _plugins[ ++iter ] ) ){
            env_string += ( tp.name + "," )
          }
          return env_string.indexOf("Flash") > -1
        //For InternetExplorer
        }else if( ie ){
          
          try{
            return ( new ActiveXObject("ShockwaveFlash.ShockwaveFlash") ) ? true : false;
          }catch( e ){
            return false;
          }
          
        }
      })(),
      ipad    =   agent.indexOf( "iPad" ) > -1,
      iphone  =   agent.indexOf( "iPhone" ) > -1

  //IE alwways return empty string. Use debug only.
  this.getPlugins = function(){
    return env_string
  }
  this.switch_if = function( obj ){
    if( obj.appleMobile && !hasFlash ){
      if( ipad || iphone ){
        return obj.appleMobile();
      }
    }
    if( obj.flashDisabled ){
      if( !hasFlash ){
        return obj.flashDisabled()
      }
    }
    if( obj.flashEnabled ){
      if( hasFlash ){
        return obj.flashEnabled();
      }
    }
  }
  
  //Expose $f_env to global
  win.$f_env = this;
  
}).call( {} , window , navigator.plugins , navigator.userAgent , "" )

