/// <reference path="a11y/a11y.js"/>
/// <reference path="jquery.js"/>
/// <reference path="scorm/1.2.js"/>
/// <reference path="scorm/2004.js"/>
var sco = {

  api: new ScormAdapter(),

  open: function() {
    if (!this.window || this.window.closed)
      this.window = self.open(
        this.url, "course",
        "top=0,left=0,width=" +
        this.width + ",height=" +
        this.height + ",status=no," +
        "help=no,resizable=no,scrollbars=no"
      );
    else
      alert(
        'A module of the course is already open in another window.\n\n' +
        'While holding down the "Alt" key, press the "Tab" key to bring other windows to the front.  \n\nIf you have more than one application open, you may need to press "Tab" more than once before the course page is brought to the top.\n\n' +
        'The application you are moving to is indicated on the bottom of the selection box (in the center of your screen).\n\n' +
        'When you access a page that states "'+ this.window.document.title +'" release the "Tab" and "Alt" keys and the course page will come to the front.'
      );
  },

  close: function() {
    try { this.window.close(); }
    catch (ignore) { }
  },

  // overridden by inline script
  width:  790,
  height: 534,
  url: "about:blank",
  urls: {
    splash : "sco1-ui-splash.html",
    ui     : "sco1-ui.html"
  }

};

$(self).load(function() {
  sco.api.initialize();
  sco.uri = sco.api.bookmark();
  sco.url = sco.urls[sco.uri ? "ui" : "splash"];
  $('<div style="position:absolute;top:0;left:0;width:20px;height:10px;border:solid 1px #fff;" title="current build: '+ uri.build +'"></div>').appendTo("body");
});

$(self).unload(function() {
  sco.api.terminate();
});

// hta resize/position code
if (self.hta && hta.commandLine) try {
  width  = parseFloat(self.width  || hta.width  || 800);
  height = parseFloat(self.height || hta.height || 572);
  if (ie > 6) { height += 10; width += 10; }
  resizeTo(width, height);
  moveTo(screen.availWidth - width, 0);
  moveTo(
    (screen.availWidth - width)/2,
    (screen.availHeight - height)/2
  );
} catch (mouseEventGlitch) { }

// bake in a11y classNames
if (self.a11y) {
  a11y.url = uri.script + "a11y/a11y.jpg";
  a11y(function(o) {
    $("body")
      [o.backgroundImages ? "removeClass" : "addClass"]("backgroundImages-disabled")
      [o.highContrastMode ? "addClass" : "removeClass"]("highContrastMode-enabled");
  });
}