with (classes) {
//
with (OCP) {
//
OCP.Application = function ()
{
 with (GUI.Common.Alignable) call(this, AlignClient, null, 800, 640);
 with (XHTML.events) call(this, click);

 with (Application)
 {
  // Event Handlers

  this[XHTML.events.click + "ed"] = click;

  this[Footer.Events.copyrightRequest] =
  this[Page.Events.copyrightRequest] = copyrightRequested;
  this[Page.Events.abbreviationRequest] = abbreviationRequested;
  this[Page.Events.contributorRequest] = contributorRequested;
  this[Page.Events.editionRequest] = editionRequested;
//  this[Page.Events.loaded] = pageLoaded;
  this[Page.Events.unloading] = null; // !!
  this[Page.Events.bookRequest] = bookRequested;
  this[Page.Events.linkRequest] =
  this[Navigator.Events.linkRequest] = openURL;
  this[Page.Events.pageRequest] =
  this[Navigator.Events.pageRequest] = pageRequested;
  this[Book.Events.opened] = bookOpened;
  this[Book.Events.unitSelected] = unitSelected;
  this[Book.Guide.Events.closeBook] = closeBook;
  this[Book.Guide.Events.siglaRequest] = siglaRequested;
  this[Book.Guide.Events.manuscriptSelected] = manuscriptSelected;
  this[Book.Guide.Events.copyRequest] = copyRequested;
  this[Book.Guide.Events.singleDivisionSelected] = singleDivisionSelected;
  this[Book.Guide.Events.showVariantUnitDivisions] = showVariantUnitDivisions;
  this[Book.TextGuide.Events.readingRequest] = readingRequested;
  this[Book.FragmentaryTextGuide.Events.fragmentRequested] = fragmentRequested;
  this[Book.Copy.Events.loaded] = copyLoaded;
  this[Book.CriticalApparatus.Events.closeRequested] = closeCriticalApparatus;
  this[Book.CriticalApparatus.Events.resized] = elementResized;

  // Member functions

  // Member variables

  this.The_Banner =
  this.The_Navigator =
//  this.The_Book_Guide =
  this.The_Book =
  this.The_CriticalApparatus =
  this.The_Desktop =
  this.Administration_HTMLDivElement =
  this.The_Footer =

  this.Busy_HTMLDivElement = null;

  // Constructor

  with (this)
  {
   with (ownerDocument)
   {
    The_Banner = Banner.construct(getElementById(id + ".The_Banner"));
    The_Navigator = Navigator.construct(getElementById(id + ".The_Navigator"));
    The_Book = Book.construct(getElementById(id + ".The_Book"));
    The_Desktop = Desktop.construct(getElementById(id + ".The_Desktop"));
    Administration_HTMLDivElement = getElementById(id + ".Administration_HTMLDivElement");
    The_Footer = Footer.construct(getElementById(id + ".The_Footer"));
    The_CriticalApparatus = Book.CriticalApparatus.construct(getElementById(id + ".The_CriticalApparatus"));

    Busy_HTMLDivElement = getElementById(id + ".Busy_HTMLDivElement")
   }

   Alignable.call(Administration_HTMLDivElement, Alignable.AlignRight, null, 210);

   The_Navigator.addObserver(this);
   The_Book.addObserver(this);
   The_Footer.addObserver(this);
   The_CriticalApparatus.addObserver(this);

   removeChild(The_Book);
   removeChild(The_CriticalApparatus);

   addObserver(this);
  }
 }

 return this;
}
//
Application.page_path = null;
Application.book_path = null;
//
Application.theme_name =
Application.defaultTheme_name = "OCP";
//
Application.copyrightPage_name = "copyright.html";
//
Application.contentDocument = dom.html2.HTMLDocument.call(document); // IE: make the document dom html2 compliant (as much as possible)
//
Application.The_LSParser = dom.ls.DOMImplementationLS.createLSParser(); // Application.contentDocument.implementation.createLSParser();
//
Application.construct = function (The_HTMLBodyElement) { return Application.call(The_HTMLBodyElement); }
//
Application.resize_timeout = null;
//
Application.main = function () { with (Application)
{
 var page_name;

 with (contentDocument.URL)
 {
  page_path = book_path = substring(0, lastIndexOf('/') + 1 || lastIndexOf('\\') + 1 || length);

  page_name = lastIndexOf('?') + 1? substring(lastIndexOf('?') + 1) : "documents";
 }

 page_path += "documents/Pages/";
 book_path += "documents/Books/";

 with (construct(The_Application = document.getElementById("The_Application")))
 {
  position();

  setTimeout(function () { try { The_Desktop.setPage(page_name + ".html"); } catch (e) {} }, 0); // Firefox workaround
 }
}}
//
Application.resize = function () { with (Application)
{
 if (! ("position_timeout" in resize)) resize.position_timeout = null; // static local variable

 if (resize.position_timeout) return;

 resize.position_timeout = setTimeout(function () { resize.position_timeout = null; The_Application.position(); }, 0);
}}
//
Application.close = function () { with (Application)
{
 // if (The_Desktop.get_Book()) prompt(); // Add a bookmark
}}
//
Application.click = function (The_MouseEvent, Sending_Object) { with (Application) with (this)
{
 if (Sending_Object != this) return;

 var Clicked_HTMLElement = The_MouseEvent.target;

 switch (Clicked_HTMLElement)
 {
  default: with (Clicked_HTMLElement) switch (tagName.toLowerCase())
  {
   case "a": openURL(href);
    break;
   default:;
  }
 }
}}
//
Application.bookRequested = function (book_name) { with (Application) with (this)
{
 style.cursor = "wait";

 Busy_HTMLDivElement.style.display = "block";

 setTimeout(function () { The_Book.open(book_name); }, 0);
}}
//
Application.bookOpened = function (The_dom_Document /*, The_Book */) { with (Application) with (this)
{
 if (The_Book.parentNode == The_Desktop) return; // !!

 The_Desktop.setBook(The_Book);

 var Version_Element = The_dom_Document.getElementsByTagName("version").item(0); // !!

 var The_Book_Guide = Book.Guide.create(The_Book, Version_Element); replaceChild(The_Book_Guide, The_Navigator);

 removeChild(The_Banner);
 removeChild(Administration_HTMLDivElement);

 The_CriticalApparatus.showHelp();

 replaceChild(The_CriticalApparatus, The_Footer);

 position();

 The_Book_Guide.addObserver(this);

 The_Book.showDivision();

 Busy_HTMLDivElement.style.display = "none";

 style.cursor = "auto";
}}
//
// Change this to actually pass the Unit, not the unit (the element not the identifier)
//
Application.unitSelected = function (selected_Book_unit) { with (Application) with (this)
{
 switch (The_Book.the_textStructure)
 {
  case Book.criticalApparatus_textStructure:
  { /*
   var Current_CriticalApparatus = The_CriticalApparatus;

   The_CriticalApparatus = Book.CriticalApparatus.create(The_Book.getUnit_Element(selected_Book_unit));

   replaceChild(The_CriticalApparatus, Current_CriticalApparatus? Current_CriticalApparatus : The_Footer);

   position(); */

   The_CriticalApparatus.showUnit(The_Book.getUnit_Element(selected_Book_unit));

   if (The_Footer.parentNode == this)
   {
    replaceChild(The_CriticalApparatus, The_Footer);

    position();
   }
  }
   break;
  default:;
 }
}}
//
Application.closeBook = function (The_Book_Guide) { with (Application) with (this)
{
 if (/* The_Book && */ The_Book.parentNode == The_Desktop)
 {
  if (The_CriticalApparatus.parentNode == this) // if (The_CriticalApparatus)
  {
   replaceChild(The_Footer, The_CriticalApparatus);

   // The_CriticalApparatus = null;
  }

  insertBefore(The_Banner, The_Footer);

  replaceChild(The_Navigator, The_Book_Guide);

  insertBefore(Administration_HTMLDivElement, The_Desktop);

  The_Book.close();

  position();
 }
}}
//
Application.readingRequested = function (from_positions, to_positions /*, The_Book_Guide */) { with (Application) with (this)
{ /*
 if (The_CriticalApparatus.parentNode == this) // if (The_CriticalApparatus)
 {
  replaceChild(The_Footer, The_CriticalApparatus);

  // The_CriticalApparatus = null;

  position();
 }
*/
 try { The_Book.showReading(from_positions, to_positions); } catch (e) {}
}}
//
Application.fragmentRequested = function (fragment_number /*, The_Book_Guide*/) { with (Application) with (this)
{
 try { The_Book.showFragment(fragment_number); } catch (e) {}
}}
//
Application.showVariantUnitDivisions = function (show /*, The_Book_Guide */) { with (Application) with (this)
{
 try { The_Book.showVariantUnitDivisions(show); } catch (e) {}
}}
//
Application.manuscriptSelected = function (the_Book_manuscript, The_Book_Guide) { with (Application) with (this)
{ /*
 if (The_CriticalApparatus)
 {
  replaceChild(The_Footer, The_CriticalApparatus);

  The_CriticalApparatus = null;

  position();
 } */

 try { The_Book.showManuscript(the_Book_manuscript); } catch (e) {}
}}
//
Application.copyRequested = function () { with (Application) with (this)
{
 ownerDocument.defaultView.open("objects/OCP.Book.Copy.html", "OCP_Book_Copy");
}}
//
Application.singleDivisionSelected = function (bookDivision_number, The_Book_Guide) { with (Application) with (this)
{ /*
 if (The_CriticalApparatus)
 {
  replaceChild(The_Footer, The_CriticalApparatus);

  The_CriticalApparatus = null;

  position();
 } */

 try { The_Book.showDivision(bookDivision_number); } catch (e) {}
}}
//
Application.copyrightRequested = function () { with (Application) with (this)
{
 ownerDocument.defaultView.open(page_path + copyrightPage_name, "copyright"); // IE doesn't like .'s in the title parameter
}}
//
Application.abbreviationRequested = function (abbreviation_name) { with (Application) with (this)
{
 ownerDocument.defaultView.open(page_path + "abbreviations.html#" + abbreviation_name, "abbreviations");
}}
//
Application.contributorRequested = function (contributor_name) { with (Application) with (this)
{
 ownerDocument.defaultView.open(page_path + "contributors.html#" + contributor_name, "contributors");
}}
//
Application.editionRequested = function (book_name) { with (Application) with (this)
{
 ownerDocument.defaultView.open(page_path + "editions.html#" + book_name, "editions");
}}
//
Application.siglaRequested = function (book_name) { with (Application) with (this)
{
 var page_name;

 // Ugly hack time :)
 switch (book_name)
 {
  case "TAbA":
  case "TAbB": page_name = "TAbr";
   break;
  case "Baru":
  case "2Bar-Syr": page_name = "2Bar";
   break;
  default: page_name = book_name;
 }

 ownerDocument.defaultView.open(page_path + page_name + ".html#symbols", "sigla");
}}
//
Application.pageRequested = function (page_name, Sending_Object) { with (Application) with (this)
{
 switch (page_name)
 {
//  case copyrightDocument_name: copyrightRequested();
//   break;
  default: with (The_Desktop)
  {
   /* style.visibility = "hidden"; */ setPage(page_name);
  }
 }
}}
//
Application.closeCriticalApparatus = function () { with (Application) with (this)
{
 if (The_CriticalApparatus.parentNode == this)
 {
  replaceChild(The_Footer, The_CriticalApparatus);

  position();
 }
}}
//
Application.elementResized = function (Resized_Element) { with (Application) with (this)
{
 var This_Element = Resized_Element;

 while (This_Element)
 {
  if (This_Element.Alignable) This_Element.position();

  This_Element = This_Element.nextSibling;
 }
}}
//
Application.copyLoaded = function (Copy_Document) { with (Application) with (this)
{
 var Book_Node = Copy_Document.importNode(The_Book, true);

 Copy_Document.body.appendChild(Book_Node);
}}
//
Application.openURL = function (the_href) { with (Application) with (this)
{
 ownerDocument.defaultView.open(the_href);
}}
//
var The_Application;
//
}
//
}
//
onload = OCP.Application.main;
onresize = OCP.Application.resize;
onunload = OCP.Application.close;
