// Documentation & updates available at:
// http://codecentre.eplica.is/js/eolasfix/test.htm

(function () {
  // run only once!
  if (window.__Eolas_Fixed) { return; }
  __Eolas_Fixed = 1;

  var doc = document,                                // minifier alias
      getElementsByTagName = 'getElementsByTagName', // minifier alias
      outerHTML = 'outerHTML',                       // minifier alias
      tags = ['object','embed','applet'],  // tags to "fix"
      x = -1, y, z,
      elm, paramElm, paramsHTML,
  eolasfix = function ()
  {
    // for each tag name specified in Array t
    while (tags[++x])
    {
      // find all elements of that type in the document
      // loop through the elements
      y = 0;
      while (elm = doc[getElementsByTagName](tags[x])[y++])
      {
        paramsHTML = "";
        z = 0;
        // sometimes <param> elements don't show up in innerHTML
        if (!/<p/i.test(elm[outerHTML]))
        {
          // and then we need to collect their outerHTML.
          while (paramElm = elm[getElementsByTagName]('param')[z++])
          {
            paramsHTML += paramElm[outerHTML];
          }
        }
        // Then clone and replace the `elm` in the DOM and insert `paramHTML`.
        elm[outerHTML] = elm[outerHTML].replace(/>/, '>'+paramsHTML);
      }
    }
  };

  0/*@cc_on + 1 @*/ && eolasfix();
                          // if is_ie, then run the fix straight away 
                          // (because the defer="defer" attribute has delayed
                          // execution until the DOM has loaded)
  window.opera && doc.addEventListener('DOMContentLoaded', eolasfix, 0);
                          // else if we're running Opera, then set an
                          // `DOMContentLoaded` event to run the fix.

})();