// We DO NOT emit the object tag as Quicktime scripts do by default, because if we do then we lose progressive loading
// in Firefox. What we do instead is we detect IE and emit ONLY the object tag for it, and embed for the rest
function QT_WriteOBJECT() {
  
  // first get the script element we're inside of
  var allScripts = document.getElementsByTagName('script');
  var me = allScripts[allScripts.length -1];

// if (typeof(window.ActiveXObject) != 'undefined') {
//    var injectedNode = document.createElement('object');
//    injectedNode.setAttribute('classid', "clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B");
//    injectedNode.setAttribute('codebase', "http://www.apple.com/qtactivex/qtplugin.cab");
//    var attrFunc = _pairToParam;
// } else {
     var injectedNode = document.createElement('embed');
     injectedNode.appendChild(document.createTextNode('Quicktime'));
     var attrFunc = _pairToAttribute;
//  }
  
  // odd arguments are attributes, even arguments are values
  for(var i = 0; i < arguments.length; i++) {
    if((i % 2) == 0) {
      attrFunc(injectedNode, arguments[i], arguments[i+1]);
    }
  }
  me.parentNode.insertBefore(injectedNode, me);
}

function _pairToAttribute(intoNode, key, value) {
  intoNode.setAttribute(key, value);
}

function _pairToParam(intoNode, key, value) {
  // Check against the list of params which always go into the attributes
  switch(key) {
    case 'width':
      _pairToAttribute(intoNode, key, value);
      break;
    case 'height':
      _pairToAttribute(intoNode, key, value);
      break;
    default:
      var paramNode = document.createElement('param');
      paramNode.setAttribute('name', key);
      paramNode.setAttribute('value', value);
      intoNode.appendChild(paramNode);
  }
}