// SWFobject for IPS by sveinung@idium.no Aug 2010
(function() {
  window.ips = window.ips || {};
  window.ips.queue = window.ips.queue || [];
  window.ips.swfQueueHandler = function swfQueueHandler(obj) {
    var setup = obj || {
      "loading": false
    },
      queueChecker;
    if (typeof window.swfobject !== 'undefined' && typeof window.swfobject.embedSWF !== 'undefined') {
      setup.loading = false;
    } else if (ips.queue.length > 0) {
      if (setup.loading === false) {
        var swf = document.createElement('script');
        swf.type = 'text/javascript';
        swf.async = true;
        swf.src = 'http://ajax.googleapis.com/ajax/libs/swfobject/2.2/swfobject.js';
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(swf);
        setup.loading = true;
      }
      queueChecker = setTimeout(function() {
        swfQueueHandler(setup);
      },
      50);
    }
    if (setup.loading === false && ips.queue.length > 0) {
      for (var i = 0; i < ips.queue.length; i++) {
        var swfo = ips.queue[i];
        if (!swfo.loaded) {
          swfobject.embedSWF(swfo.url, swfo.element, swfo.width, swfo.height, swfo.version, swfo.expressInstall, swfo.flashvars, swfo.params, swfo.attributes);
          swfo.loaded = "true";
        }
      }
    }
    //Not working right?
    if (typeof window.jQuery !== 'undefined') {
      jQuery(document).one('ajaxStart ajaxStop', function() {
        queueChecker = setTimeout(function() {
          swfQueueHandler(setup);
        },
        100);
      });
    }
  }
})();



