with (classes) {
//
with (OCP) {
//
with (Book) {
//
Book.Guide = function (The_Book, Version_Element)
{
 with (GUI.Common.Alignable) call(this, AlignLeft, null, 320);
 with (XHTML.events) call(this, click);

 with (Guide)
 {
  // Event handlers

  this[XHTML.events.click + "ed"] = click;
  this[XHTML.Form.Button.events.click] = buttonClicked;
  this[XHTML.Form.CheckboxInput.events.change] = checkboxChanged;

  this[Book.Events.textShown] = enable;

  // Methods

  this.toggleFieldset = toggleFieldset;

  this.enable = enable;
  this.disable = disable;

  // Member variables

  this.The_XPathEvaluator = null;

  this.The_Book = The_Book;

  this.Version_Element = Version_Element;

  with (this)
  {
   with (elements) try
   {
    this.ToggleManuscripts_Button = namedItem("ToggleManuscripts_Button");

    this.CloseBook_Button = namedItem("CloseBook_Button");
    this.ShowSigla_Button = namedItem("ShowSigla_Button");
    this.ToggleSelectDivision_Button = namedItem("ToggleSelectDivision_Button");

    this.PrinterFriendly_Button = namedItem("PrinterFriendly_Button");
    this.ShowVariantUnitDivisions_CheckboxInput = namedItem("ShowVariantUnitDivisions_CheckboxInput");

   } catch (e) { /* IE defines these automatically (not a good thing) */ }

   The_XPathEvaluator = new dom.xpath.XPathEvaluator;

   if (CloseBook_Button) /* Opera workaround */ with (XHTML.Form)
   {
    if (this.ToggleManuscripts_Button) Button.call(ToggleManuscripts_Button).addObserver(this);

    Button.call(CloseBook_Button).addObserver(this);
    Button.call(ShowSigla_Button).addObserver(this);
    Button.call(ToggleSelectDivision_Button).addObserver(this);
    Button.call(PrinterFriendly_Button).addObserver(this);

    CheckboxInput.call(ShowVariantUnitDivisions_CheckboxInput).addObserver(this);
   }

   The_Book.addObserver(this);

   addObserver(this);
  }
 }

 return this;
}
//
Guide.number = Book.number;
//
Guide.the_stylesheet = "classes/OCP/Book/Guide.xsl";
//
Guide.The_XSLTProcessor = null;
//
Guide.Events =
{
 manuscriptSelected : "OCP_Book_Guide_manuscriptSelected",
 singleDivisionSelected : "OCP_Book_Guide_singleDivisionSelected",
 copyRequest : "OCP_Book_Guide_copyRequest",
 showVariantUnitDivisions : "OCP_Book_Guide_showVariantUnitDivisions",
 siglaRequest : "OCP_Book_Guide_siglaRequest",
 closeBook : "OCP_Book_Guide_closeBook"
}
//
// Guide.construct = function (The_HTMLFormElement) { return Guide.call(The_HTMLFormElement); }
//
Guide.create = function (The_Book, Version_Element) { with (Guide)
{
 if (! The_XSLTProcessor)
 {
  The_XSLTProcessor = new XML.XSLTProcessor;
/*
  var Stylesheet_Document = Application.contentDocument.implementation.createDocument(null, null, null);

  with (Stylesheet_Document) { async = false; load(the_stylesheet); }
*/
  var Stylesheet_Document = Application.The_LSParser.parseURI(the_stylesheet);

  The_XSLTProcessor.importStylesheet(Stylesheet_Document);
 }

 var Guide_Element = The_XSLTProcessor.transformToDocument(Version_Element.parentNode).documentElement; // Version_Element // Safari workaround

 var The_HTMLFormElement = Application.contentDocument.importNode(Guide_Element, true); // adoptNode not implemented in FF, IE

 var Guide_T = eval(The_HTMLFormElement.className);

 Guide_T.call(The_HTMLFormElement, The_Book, Version_Element);

 if (! The_HTMLFormElement.CloseBook_Button) // Opera workaround
  setTimeout(function () { Guide_T.call(The_HTMLFormElement, The_Book, Version_Element); }, 0);

 return The_HTMLFormElement;
}}
//
Guide.click = function (The_MouseEvent, Sending_Element) { with (Guide) with (this)
{
 if (Sending_Element != this) return;

 var Clicked_Element = The_MouseEvent.target;

 switch (Clicked_Element.tagName.toLowerCase())
 {
  case "a": switch (Clicked_Element.className)
  {
   case "manuscript": disable(); broadcastAsync(Events.manuscriptSelected, Book.manuscript(Clicked_Element.firstChild.nodeValue));
    break;
   default: alert(target.className);
  }
   break;
  case "td": if (Clicked_Element.className == "number")
  {
   disable(); broadcastAsync(Events.singleDivisionSelected, Book.number(Clicked_Element.firstChild.nodeValue));
  }
   break;
  default:;
 }
}}
//
Guide.toggleFieldset = function (Toggle_HTMLButtonElement, This_HTMLElement) { with (Guide) with (this)
{
 var minimized = This_HTMLElement.className.indexOf("minimized") != -1;

 Toggle_HTMLButtonElement.firstChild.nodeValue = minimized? "-" : "+";

 with (This_HTMLElement) className = minimized? className.replace("minimized", "") : className + "minimized";
}}
//
Guide.buttonClicked = function (Clicked_Button) { with (Guide) with (this)
{
 switch (Clicked_Button)
 {
  case CloseBook_Button: disable(); The_Book.removeObserver(this); broadcastAsync(Events.closeBook);
   break;
  case ShowSigla_Button: broadcast/*Async*/(Events.siglaRequest, The_Book.get_name()); // Safari workaround
   break;
  case ToggleManuscripts_Button:
  case ToggleSelectDivision_Button: toggleFieldset(Clicked_Button, Clicked_Button.parentNode.parentNode);
   break;
  case PrinterFriendly_Button: broadcast/*Async*/(Events.copyRequest); // Safari workaround
   break;
  default:;
 }
}}
//
Guide.checkboxChanged = function (Changed_CheckboxInput) { with (Guide) with (this)
{
 switch (Changed_CheckboxInput)
 {
  case ShowVariantUnitDivisions_CheckboxInput:
  {
   disable(); broadcastAsync(Events.showVariantUnitDivisions, ShowVariantUnitDivisions_CheckboxInput.checked);
  }
   break;
  default:;
 }
}}
//
Guide.enable = function () { with (Guide) with (this) { disabled = false; style.cursor = ""; }}
Guide.disable = function () { with (Guide) with (this) { style.cursor = "wait"; disabled = true; }}
//
}
//
}
//
}
