function PodGardenPlayer() {
  function Options() {
    var compact         = false;
    var compact_dim     = [ 333, 77 ];
    var config          = 'config.xml';
    var full_dim        = [ 565, 327 ];
    var id              = 'MediaPlayer';
    var instanceVar     = 'pgPlayer';
    var paused          = false;
    var pgColor         = 'dark';
    var playerVersion   = 7;
    var sidebar         = '';
    var sponsored       = true;
    var swf_bg          = '#FFFFFF';
    var swf_id_ext      = '_swf';
    var swf_path        = 'http://podgarden.oneupweb.com/services/media_players/springgreen/MediaPlayer.swf';

    function swf_id() {
      return id + swf_id_ext;
    };
    function shell_id() {
      return id + '_shell';
    };
    function getSidebar() {
      var sbO       = document.getElementById(sidebar);
      var contents  = '';
      if (sbO) {
        contents    = sbO.innerHTML;
        sbO.style.display = 'none';
      }
      return contents;
    };
    this.id = function() {
      return id;
    };
    this.merge = function(opts) {
      for (var k in opts) {
        switch(k.toLowerCase()) {
          case 'color':
            pgColor = opts[k];
            break;
          case 'compact':
            compact = opts[k];
            break;
          case 'sponsored':
            sponsored = opts[k];
            break;
          case 'id':
            id = opts[k];
            break;
          case 'config':
            config = opts[k];
            break;
          case 'sidebar':
            sidebar = opts[k];
            break;
          case 'bg':
            swf_bg = opts[k];
            break;
          case 'paused' :
            paused = opts[k];
            break;
        };
      }
    };
    function className() {
      var cn = (compact) ? " pgCompact" : (sponsored) ? " pgSponsorship" : "";
      return "pgContainer"+cn;
    };
    this.injectHTML = function() {
      with (document) {
        write('<div class="'+className()+'" id="' + shell_id() + '">');
        write('<div class="pgFlash" id="' + id + '"><h3>Flash Player Required</h3></div>');
        write('<div class="pgSidebar" id="'+id+'_sidebarID">');
        write('<div class="pgSidebar_scroller">');
        write('<div class="pgSidebar_content pgStyles">' + getSidebar() + '</div></div>');
        write('<div class="pgSidebar_sponsorship">');
        write('<a href="http://www.podgarden.com" target="_blank"><img src="http://assets.podtractor.com/mediaplayer/images/btyb_podgarden_' + pgColor + '.gif" alt="Brought to you by Podgarden&trade;" /></a>');
        write('</div></div></div>');
      }
    };
    this.injectSWF = function(feedItem, feedItemProgress) {
      var swfObject = new SWFObject(swf_path, swf_id(), full_dim[0], full_dim[1], playerVersion, swf_bg)

      swfObject.addParam('menu' , 'false');
      swfObject.addParam('scale', 'false');
      swfObject.addParam('wmode', 'transparent');

      swfObject.addVariable('autoPlay', paused);
      swfObject.addVariable('compact', (compact) ? 'true' : 'false');
      swfObject.addVariable('configFile', config);
      swfObject.addVariable('containerID', id);
      swfObject.addVariable('instanceVar', instanceVar);
      swfObject.addVariable('seekItem', feedItem);
      swfObject.addVariable('seekItemSeconds', feedItemProgress);

      swfObject.write(id);
    };
    this.toggleMode = function(feedItem,feedItemProgress) {
      /*
      if (pop_up) {
        var h    = 'height=' + (full_dim[1] + 40);
        var w    = 'width='  + (full_dim[0] + 40) + ',' ;
        var opts = ',menubar=0,toolbar=0,status=0,scrollbars=1,resizable=1';
        win      = window.open('', 'pgWindow', w + h + opts);

        with (win.document) {
          write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">');
          write('<html><head><title>Media Player</title>');
          write('<link rel="stylesheet" type="text/css" href="http://podgarden.oneupweb.com/services/media_players/springgreen/MediaPlayer.css" />');
          write('</head><body id="pgPlayer_popup">');
        }

        this.injectHTML();
        this.injectSWF();

        with (win.document) {
          write('</body></html>');
          close();
        }
      } else {
      */
        swf = document.getElementById(swf_id());
        var prnt = swf.parentNode;
        prnt.removeChild(swf);

        var current_dimensions  = (compact) ? compact_dim : full_dim;
        var target_dimensions   = (compact) ? full_dim    : compact_dim;

        var box = document.createElement('div');
        box.style.width   = (current_dimensions[0]-2) + 'px';
        box.style.height  = (current_dimensions[1]-2) + 'px';
        box.style.borderWidth = '1px';
        box.style.borderStyle = 'solid';
        box.style.borderColor = '#000000';
        box.style.opacity     = 0.50;
        box.style.filter      = 'alpha(opacity='+50+')';
        prnt.appendChild(box);

        box.ws = current_dimensions[0];
        box.we = target_dimensions[0];
        box.hs = current_dimensions[1];
        box.he = target_dimensions[1];
        box.ww = box.ws;
        box.hh = box.hs;
        box.wd = box.ws > box.we;
        box.hd = box.hs > box.he;
        box.style.width = box.ws + 'px';
        box.style.height = box.hs + 'px';
        var wdone = false;
        var hdone = false;

        var mySelf = this;
        box.fxscale = setInterval(function() {
            if (!wdone) {
              box.ww = ((box.we-box.ww)/5)+box.ww;
              box.ww = (!box.wd) ? Math.ceil(box.ww) : Math.floor(box.ww);
              box.style.width = box.ww + 'px';
              if ((box.wd && (box.ww <= box.we)) || (!box.wd && (box.ww >= box.we))) {
                wdone = true;
              }
            }
            if (!hdone) {
              box.hh = ((box.he-box.hh)/5)+box.hh;
              box.hh = (!box.hd) ? Math.ceil(box.hh) : Math.floor(box.hh);
              box.style.height = box.hh + 'px';
              if ((box.hd && (box.hh <= box.he)) || (!box.hd && (box.hh >= box.he))) {
                hdone = true;
              }
            }
            if (wdone && hdone) {
              clearInterval(box.fxscale);
              compact = !compact;
              document.getElementById(shell_id()).className = className();
              mySelf.injectSWF(feedItem, feedItemProgress);
              if (!compact) {
                mySelf.showSidebar();
              }
            }
        }, 10);
      //}
    };
    this.hideSidebar = function() {
      var sbr = document.getElementById(id+'_sidebarID');
      sbr.style.display = 'none';
    };
    this.showSidebar = function() {
      var sbr = document.getElementById(id+'_sidebarID');
      sbr.style.display = 'block';
    };
  };

  // private variables
  var history = new Array();

  // Constructor-ish function
  function MediaPlayerSetup() {
    document.write('<link rel="stylesheet" type="text/css" href="http://podgarden.oneupweb.com/services/media_players/springgreen/MediaPlayer.css" />');
  };

  MediaPlayerSetup();

  // public function definitions
  this.build = function(id, bg, config, sidebar, compact, paused, sponsored, color) {
    var options = new Options();
    options.merge({
        'color': color,
        'compact': compact,
        'config': config,
        'id': id,
        'paused': paused,
        'sidebar': sidebar,
        'sponsored': sponsored,
        'swf_bg': bg
        });

    history.push({'key': options.id(), 'options': options});
  };

  this.toggleMode = function(container, feedItem, feedItemProgress) {
    findPlayer(container).toggleMode(feedItem, feedItemProgress);
  };
  this.showSidebar = function(container) {
    findPlayer(container).showSidebar();
  };
  this.hideSidebar = function(container) {
    findPlayer(container).hideSidebar();
  };
  function findPlayer(id) {
    for (var i=0; i < history.length; i++) {
      if (history[i].key == id) {
        return history[i].options;
      }
    }
  };

  this.write = function() {
    if (history.length>0) {
      injectHTML();
      injectSWF();
    }
  };

  function injectHTML() {
    history[history.length-1].options.injectHTML();
  };

  function injectSWF() {
    history[history.length-1].options.injectSWF(0,0);
  };

};

/**
 * SWFObject v1.4.4: Flash Player detection and embed - http://blog.deconcept.com/swfobject/
 *
 * SWFObject is (c) 2006 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 * **SWFObject is the SWF embed script formerly known as FlashObject. The name was changed for
 *   legal reasons.
 */
if(typeof deconcept == "undefined") var deconcept = new Object();
if(typeof deconcept.util == "undefined") deconcept.util = new Object();
if(typeof deconcept.SWFObjectUtil == "undefined") deconcept.SWFObjectUtil = new Object();
deconcept.SWFObject = function(swf, id, w, h, ver, c, useExpressInstall, quality, xiRedirectUrl, redirectUrl, detectKey){
  if (!document.getElementById) { return; }
  this.DETECT_KEY = detectKey ? detectKey : 'detectflash';
  this.skipDetect = deconcept.util.getRequestParameter(this.DETECT_KEY);
  this.params = new Object();
  this.variables = new Object();
  this.attributes = new Array();
  if(swf) { this.setAttribute('swf', swf); }
  if(id) { this.setAttribute('id', id); }
  if(w) { this.setAttribute('width', w); }
  if(h) { this.setAttribute('height', h); }
  if(ver) { this.setAttribute('version', new deconcept.PlayerVersion(ver.toString().split("."))); }
  this.installedVer = deconcept.SWFObjectUtil.getPlayerVersion();
  if(c) { this.addParam('bgcolor', c); }
  var q = quality ? quality : 'high';
  this.addParam('quality', q);
  this.setAttribute('useExpressInstall', useExpressInstall);
  this.setAttribute('doExpressInstall', false);
  var xir = (xiRedirectUrl) ? xiRedirectUrl : window.location;
  this.setAttribute('xiRedirectUrl', xir);
  this.setAttribute('redirectUrl', '');
  if(redirectUrl) { this.setAttribute('redirectUrl', redirectUrl); }
};
deconcept.SWFObject.prototype = {
  setAttribute: function(name, value){
    this.attributes[name] = value;
  },
  getAttribute: function(name){
    return this.attributes[name];
  },
  addParam: function(name, value){
    this.params[name] = value;
  },
  getParams: function(){
    return this.params;
  },
  addVariable: function(name, value){
    this.variables[name] = value;
  },
  getVariable: function(name){
    return this.variables[name];
  },
  getVariables: function(){
    return this.variables;
  },
  getVariablePairs: function(){
    var variablePairs = new Array();
    var key;
    var variables = this.getVariables();
    for(key in variables){
      variablePairs.push(key +"="+ variables[key]);
    }
    return variablePairs;
  },
  getSWFHTML: function() {
    var swfNode = "";
    if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
      if (this.getAttribute("doExpressInstall")) { this.addVariable("MMplayerType", "PlugIn"); }
      swfNode = '<embed type="application/x-shockwave-flash" src="'+ this.getAttribute('swf') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'"';
      swfNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
      var params = this.getParams();
       for(var key in params){ swfNode += [key] +'="'+ params[key] +'" '; }
      var pairs = this.getVariablePairs().join("&");
       if (pairs.length > 0){ swfNode += 'flashvars="'+ pairs +'"'; }
      swfNode += '/>';
    } else { // PC IE
      if (this.getAttribute("doExpressInstall")) { this.addVariable("MMplayerType", "ActiveX"); }
      swfNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'">';
      swfNode += '<param name="movie" value="'+ this.getAttribute('swf') +'" />';
      var params = this.getParams();
      for(var key in params) {
       swfNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
      }
      var pairs = this.getVariablePairs().join("&");
      if(pairs.length > 0) {swfNode += '<param name="flashvars" value="'+ pairs +'" />';}
      swfNode += "</object>";
    }
    return swfNode;
  },
  write: function(elementId){
    if(this.getAttribute('useExpressInstall')) {
      // check to see if we need to do an express install
      var expressInstallReqVer = new deconcept.PlayerVersion([6,0,65]);
      if (this.installedVer.versionIsValid(expressInstallReqVer) && !this.installedVer.versionIsValid(this.getAttribute('version'))) {
        this.setAttribute('doExpressInstall', true);
        this.addVariable("MMredirectURL", escape(this.getAttribute('xiRedirectUrl')));
        document.title = document.title.slice(0, 47) + " - Flash Player Installation";
        this.addVariable("MMdoctitle", document.title);
      }
    }
    if(this.skipDetect || this.getAttribute('doExpressInstall') || this.installedVer.versionIsValid(this.getAttribute('version'))){
      var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
      n.innerHTML = this.getSWFHTML();
      return true;
    }else{
      if(this.getAttribute('redirectUrl') != "") {
        document.location.replace(this.getAttribute('redirectUrl'));
      }
    }
    return false;
  }
};

/* ---- detection functions ---- */
deconcept.SWFObjectUtil.getPlayerVersion = function(){
  var PlayerVersion = new deconcept.PlayerVersion([0,0,0]);
  if(navigator.plugins && navigator.mimeTypes.length){
    var x = navigator.plugins["Shockwave Flash"];
    if(x && x.description) {
      PlayerVersion = new deconcept.PlayerVersion(x.description.replace(/([a-zA-Z]|\s)+/, "").replace(/(\s+r|\s+b[0-9]+)/, ".").split("."));
    }
  }else{
    // do minor version lookup in IE, but avoid fp6 crashing issues
    // see http://blog.deconcept.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 deconcept.PlayerVersion([6,0,21]);
        axo.AllowScriptAccess = "always"; // throws 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 deconcept.PlayerVersion(axo.GetVariable("$version").split(" ")[1].split(","));
    }
  }
  return PlayerVersion;
};
deconcept.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;
};
deconcept.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;
};
/* ---- get value of query string param ---- */
deconcept.util = {
  getRequestParameter: function(param) {
    var q = document.location.search || document.location.hash;
    if(q) {
      var pairs = q.substring(1).split("&");
      for (var i=0; i < pairs.length; i++) {
        if (pairs[i].substring(0, pairs[i].indexOf("=")) == param) {
          return pairs[i].substring((pairs[i].indexOf("=")+1));
        }
      }
    }
    return "";
  }
};
/* fix for video streaming bug */
deconcept.SWFObjectUtil.cleanupSWFs = function() {
  if (window.opera || !document.all) return;
  var objects = document.getElementsByTagName("OBJECT");
  for (var i=0; i < objects.length; i++) {
    objects[i].style.display = 'none';
    for (var x in objects[i]) {
      if (typeof objects[i][x] == 'function') {
        objects[i][x] = function(){};
      }
    }
  }
};
// fixes bug in fp9 see http://blog.deconcept.com/2006/07/28/swfobject-143-released/
deconcept.SWFObjectUtil.prepUnload = function() {
  __flash_unloadHandler = function(){};
  __flash_savedUnloadHandler = function(){};
  if (typeof window.onunload == 'function') {
    var oldUnload = window.onunload;
    window.onunload = function() {
      deconcept.SWFObjectUtil.cleanupSWFs();
      oldUnload();
    };
  } else {
    window.onunload = deconcept.SWFObjectUtil.cleanupSWFs;
  }
};
if (typeof window.onbeforeunload == 'function') {
  var oldBeforeUnload = window.onbeforeunload;
  window.onbeforeunload = function() {
    deconcept.SWFObjectUtil.prepUnload();
    oldBeforeUnload();
  };
} else {
  window.onbeforeunload = deconcept.SWFObjectUtil.prepUnload;
}
/* add Array.push if needed (ie5) */
if (Array.prototype.push == null) { Array.prototype.push = function(item) { this[this.length] = item; return this.length; };}

/* add some aliases for ease of use/backwards compatibility */
var getQueryParamValue = deconcept.util.getRequestParameter;
var FlashObject = deconcept.SWFObject; // for legacy support
var SWFObject = deconcept.SWFObject;

