swagit_player_url = '';
swagit_random = (new Date()).getTime();
swagit_org_error_handler = window.onerror;

function quoted(str) {
  return (str != null) ? '"' + str + '"' : '""';
}

function swagit_encodeURIComponent(str) {
  if (typeof(encodeURIComponent) == 'function') {
    return encodeURIComponent(str);
  } else {
    return escape(str);
  }
}

function swagit_append_url(param, value) {
  if (value) {
    window.swagit_player_url += '&' + param + '=' + value;
  }
}

function swagit_append_url_esc(param, value) {
  if (value) {
    swagit_append_url(param, swagit_encodeURIComponent(value));
  }
}

function swagit_show_player() {
  var w = window;
  w.onerror = w.swagit_org_error_handler;
  w.swagit_player_url = 'http://media.swagit.com/embed/?';
  w.swagit_player_client = w.swagit_player_client.toLowerCase();
  w.swagit_player_url += 'client=' + escape(w.swagit_player_client) + '&random=' + w.swagit_random;

  if (w.swagit_player_format) {
    swagit_append_url_esc('format', w.swagit_player_format.toLowerCase());
  }

  if (w.swagit_player_category) {
    swagit_append_url_esc('category', w.swagit_player_category.toLowerCase());
  }

  swagit_append_url('width', w.swagit_player_width);
  swagit_append_url('height', w.swagit_player_height);

  if (w.swagit_player_refid) {
    swagit_append_url('refid', w.swagit_player_refid);
  }

  document.write('<ifr' + 'ame' +
                 ' name="swagit_player_frame"' +
                 ' width=' + quoted(w.swagit_player_width) +
                 ' height=' + quoted(w.swagit_player_height) +
                 ' frameborder=' + quoted(w.swagit_player_frameborder) +
                 ' src=' + quoted(w.swagit_player_url) +
                 ' marginwidth="0"' +
                 ' marginheight="0"' +
                 ' vspace="0"' +
                 ' hspace="0"' +
                 ' allowtransparency="true"' +
                 ' scrolling="no">');
  // swagit_write_tracker('noiframe');
  document.write('</ifr' + 'ame>');
}

function swagit_error_handler(message, url, line) {
  swagit_show_player();
  return true;
}

window.onerror = swagit_error_handler;

if (window.swagit_player_frameborder == null) {
  swagit_player_frameborder = 0;
}

if (window.swagit_player_format == null) {
  swagit_player_format = swagit_player_width + 'x' + swagit_player_height;
}

swagit_show_player();
