/**
 * FlashObject v1.3c: Flash detection and embed - http://blog.deconcept.com/flashobject/
 *
 * FlashObject is (c) 2006 Geoff Stearns and is released under the MIT License:
 * http://www.opensource.org/licenses/mit-license.php
 *
 */
if(typeof com == "undefined") var com = new Object();
if(typeof com.deconcept == "undefined") com.deconcept = new Object();
if(typeof com.deconcept.util == "undefined") com.deconcept.util = new Object();
com.deconcept.AppletObject = function(url, id, w, h){
  if (!document.createElement || !document.getElementById) return;
  this.params = new Object();
  this.variables = new Object();
  this.attributes = new Array();
  this.embed = "";


  if(url) this.addParam('url', url);
  if(id) this.setAttribute('id', id);
  if(w) this.setAttribute('width', w);
  if(h) this.setAttribute('height', h);
}
com.deconcept.AppletObject.prototype = {
  addEmbed: function(name, url, id, w, h, autostart){
    this.embed = '<embed name="'+name+'" src="'+url+'" type="video/x-ms-wmv" console="'+id+'" height="'+h+'" width="'+w+'" autostart="'+autostart+'" />';
  },
  getEmbed: function(){
    return this.embed;
  },
  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;
  },
  getVariables: function(){
    return this.variables;
  },
  createParamTag: function(n, v){
    var p = document.createElement('param');
    p.setAttribute('name', n);
    p.setAttribute('value', v);
    return p;
  },
  getAppletHTML: function() {
    var appletNode = "";
    if (navigator.plugins && navigator.mimeTypes && navigator.mimeTypes.length) { // netscape plugin architecture
      appletNode = '<embed type="application/x-oleobject" src="'+ this.getAttribute('url') +'" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'"';
      appletNode += ' id="'+ this.getAttribute('id') +'" name="'+ this.getAttribute('id') +'" ';
      var params = this.getParams();
       for(var key in params){ appletNode += [key] +'="'+ params[key] +'" '; }
      flashNode += '/>';
    } else { // PC IE
      appletNode = '<object id="'+ this.getAttribute('id') +'" classid="clsid:6bf52a52-394a-11d3-b153-00c04f79faa6" width="'+ this.getAttribute('width') +'" height="'+ this.getAttribute('height') +'">';
      appletNode += '<param name="movie" value="'+ this.getAttribute('url') +'" />';
      var params = this.getParams();
      for(var key in params) {
       appletNode += '<param name="'+ key +'" value="'+ params[key] +'" />';
      }
      appletNode += this.getEmbed();
      appletNode += "</object>";
    }
    return appletNode;
  },
  write: function(elementId){
    var n = (typeof elementId == 'string') ? document.getElementById(elementId) : elementId;
    n.innerHTML = this.getAppletHTML();
  }
}

/* ---- get value of query string param ---- */
com.deconcept.util = {
  getRequestParameter: function(param){
    var q = document.location.search || document.location.hash;
    if(q){
      var startIndex = q.indexOf(param +"=");
      var endIndex = (q.indexOf("&", startIndex) > -1) ? q.indexOf("&", startIndex) : q.length;
      if (q.length > 1 && startIndex > -1) {
        return q.substring(q.indexOf("=", startIndex)+1, endIndex);
      }
    }
    return "";
  }
}

/* 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 = com.deconcept.util.getRequestParameter;
var AppletObject = com.deconcept.AppletObject;

