/*
* Flash detection from SWFObject v1.5: http://blog.deconcept.com/swfobject/
* http://www.opensource.org/licenses/mit-license.php
*/

if(typeof fmvoicepost == "undefined") var fmvoicepost = new Object();

fmvoicepost.getPlayerVersion = function(){
  var PlayerVersion = new fmvoicepost.PlayerVersion([0,0,0]);
  if(navigator.plugins && navigator.mimeTypes.length){
    var x = navigator.plugins["Shockwave Flash"];
    if(x && x.description) {
      PlayerVersion = new fmvoicepost.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
    }
  }else if (navigator.userAgent && navigator.userAgent.indexOf("Windows CE") >= 0){ // if Windows CE
    var axo = 1;
    var counter = 3;
    while(axo) {
      try {
        counter++;
        axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+ counter);
//        document.write("player v: "+ counter);
        PlayerVersion = new fmvoicepost.PlayerVersion([counter,0,0]);
      } catch (e) {
        axo = null;
      }
    }
  } else { // Win IE (non mobile)
    // do minor version lookup in IE, but avoid fp6 crashing issues
    // see http://blog.fmvoicepost.com/2006/01/11/getvariable-setvariable-crash-internet-explorer-flash-6/
    try{
      var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7");
    }catch(e){
      try {
        var axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");
        PlayerVersion = new fmvoicepost.PlayerVersion([6,0,21]);
        axo.AllowScriptAccess = "always"; // error if player version < 6.0.47 (thanks to Michael Williams @ Adobe for this code)
      } catch(e) {
        if (PlayerVersion.major == 6) {
          return PlayerVersion;
        }
      }
      try {
        axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
      } catch(e) {}
    }
    if (axo != null) {
      PlayerVersion = new fmvoicepost.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
    }
  }
  return PlayerVersion;
}

fmvoicepost.PlayerVersion = function(arrVersion){
  this.major = arrVersion[0] != null ? parseInt(arrVersion[0]) : 0;
  this.minor = arrVersion[1] != null ? parseInt(arrVersion[1]) : 0;
  this.rev = arrVersion[2] != null ? parseInt(arrVersion[2]) : 0;
}

fmvoicepost.PlayerVersion.prototype.versionIsValid = function(fv){
  if(this.major < fv.major) return false;
  if(this.major > fv.major) return true;
  if(this.minor < fv.minor) return false;
  if(this.minor > fv.minor) return true;
  if(this.rev < fv.rev) return false;
  return true;
}

fmvoicepost.VoicePost32 = function() { 
  var playerUrl        = 'http://voiceposts.fmpub.net/players/player1.swf';
  var soundUrl         = 'http://voiceposts.fmpub.net/metafilter/vp.152897625846cb58b3548e5090385396.mp3';
  var width            = 290;
  var height           = 24;
  var playerid         = 78;
  var audiotitle       = 'Listen to this voice post'; 
  var bgcolor          = "#ffffff";
  var OAzoneid         = '1292'; 
  var postid           = '78';
  var source           = 'metafilter_78';
  var click_banner_id  = '12602';
  var url              = 'http://dynamic.fmpub.net/adserver/adclick.php?bannerid=' + click_banner_id + '&zoneid=&source=' + source + '&dest=http%3A%2F%2Fvoiceposts.fmpub.net%2Fplayers%2Fclick.txt&ismap=';
  
  var validVersion = new fmvoicepost.PlayerVersion([6,0,0]);
  var actualVersion = new fmvoicepost.getPlayerVersion();
  
  if (actualVersion.versionIsValid(validVersion) == true) {
    document.write('<div id="federatedmedia_voicepost" style="width:290px;padding-top:10px;"><div id="federatedmedia_voicepost_player">');
    document.write('<object id="audioplayer' + playerid + '" data="' + playerUrl + '" type="application/x-shockwave-flash" ');
    document.write('width="' + width + '" height="' + height + '" id="FM Voice Posts" align="middle">');
    document.write('<param name="allowScriptAccess" value="always" />');
    document.write('<param name="movie" value="' + playerUrl + '" />');
    document.write('<param name="FlashVars" value="playerID=' + playerid + '&soundFile=' + soundUrl + '&audiotitle=' + audiotitle + '&url=' + escape(url) + '" />');
    document.write('<param name="quality" value="high" />');
    document.write('<param name="bgcolor" value="' + bgcolor + '" />');
    document.write('</object></div>');
    document.write('<div id="federatedmedia_voicepost_footer" style="text-align:right; width:290px; padding-top:2px;">');
    phpAds_random = new String (Math.random());
    phpAds_random = phpAds_random.substring(2,11);
    document.write ("<" + "script language='JavaScript' type='text/javascript' src='");
    document.write ("http://dynamic.fmpub.net/adserver/adjs.php?n=" + phpAds_random);
    document.write ("&amp;what=zone:" + OAzoneid + "&amp;source=" + source + "&amp;block=1&amp;blockcampaign=1");
    document.write ("&amp;exclude=" + document.phpAds_used);
    if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
    document.write ("'><" + "/script>");
    document.write('</div>');
    document.write('</div>');
  } else {
    document.write('<div id="noflash">To hear this voice post, you must <a href="http://www.adobe.com/go/getflashplayer">install Flash</a> or <a href="' + soundUrl + '">download the MP3 file</a>.</div>')
  }
}

new fmvoicepost.VoicePost32();