// style2.js: JavaScript file which uses Document Object Model to set style of text in htmlpres HTML presentation template.
// Created by Eric Krock, Netscape Communications. Permission is granted to freely reuse and distribute this file.
// Changes: - 30 July 1997 backward compatibility with Nav3.0.
//                 - 11 Sept 1997 font scaling in speakerNotes and tutorial modes.

// Calculates font size to be used for element, which is the maximum of specified*sizeMultiplier and minAllowed.
// Returns as string for storage in data structure fontSizeOf.
function calcSize (specified, sizeMult, minOK)
{  return ( Math.max (Math.round(specified*sizeMult), minOK) + "pt" )
}

// Constructor function for object type fontSizeOf. This object type holds the per-element size data
// for the current screen size.  A global variable, fontSizeOf, is set to this object so that style
// sheets in individual HTML pages can retrieve and use this data. 
function constructFontSizeOf (h1, h2, h3, h4, h5, h6, titlepage, p, li, ul, ol, dl, dt, dd, blockquote, th, td, pre, tt, small, medium, large, sizeMult, minOK)
{  this.h1 = calcSize(h1, sizeMult, minOK) 
   this.h2 = calcSize(h2, sizeMult, minOK)
   this.h3 = calcSize(h3, sizeMult, minOK)
   this.h4 = calcSize(h4, sizeMult, minOK)
   this.h5 = calcSize(h5, sizeMult, minOK)
   this.h6 = calcSize(h6, sizeMult, minOK)
   this.titlepage = calcSize(titlepage, sizeMult, minOK)
   this.p  = calcSize(p, sizeMult, minOK)
   this.li = calcSize(li, sizeMult, minOK)
   /* BUG WORKAROUND: Shouldn't be necessary to set fontSize on UL and OL as well as LI, but setting LI fontSize doesn't work now.  Setting on UL and OL is the workaround. */ 
   this.ul = calcSize(ul, sizeMult, minOK)
   this.ol = calcSize(ol, sizeMult, minOK)
   this.dl = calcSize(dl, sizeMult, minOK)
   this.dt = calcSize(dt, sizeMult, minOK)
   this.dd = calcSize(dd, sizeMult, minOK)
   this.blockquote = calcSize(blockquote, sizeMult, minOK)
   this.th = calcSize(th, sizeMult, minOK)
   this.td = calcSize(td, sizeMult, minOK)
   this.pre = calcSize(pre, sizeMult, minOK)
   this.tt  = calcSize(tt, sizeMult, minOK)
   this.small = calcSize(small, sizeMult, minOK)
   this.medium = calcSize(medium, sizeMult, minOK)
   this.large = calcSize(large, sizeMult, minOK)
}

function setFontSizes (h1, h2, h3, h4, h5, h6, titlepage, p, li, ul, ol, dl, dt, dd, blockquote, th, td, pre, tt, small, medium, large, sizeMultiplier, minFontSize)
{  var fontSizeOf = new constructFontSizeOf (h1, h2, h3, h4, h5, h6, titlepage, p, li, ul, ol, dl, dt, dd, blockquote, th, td, pre, tt, small, medium, large, sizeMultiplier, minFontSize)

	if (navigator.appName != "Microsoft Internet Explorer")   
	  {
   document.tags.H1.fontSize = fontSizeOf.h1;
   document.tags.H2.fontSize = fontSizeOf.h2;
   document.tags.H3.fontSize = fontSizeOf.h3;
   document.tags.H4.fontSize = fontSizeOf.h4;
   document.tags.H5.fontSize = fontSizeOf.h5;
   document.tags.H6.fontSize = fontSizeOf.h6;
   document.tags.PRE.fontSize = fontSizeOf.pre;
   document.tags.P.fontSize = fontSizeOf.p;

   /* BUG WORKAROUND: Shouldn't be necessary to set fontSize on UL and OL as well as LI, but setting LI fontSize doesn't work now.  Setting on UL and OL is the workaround. */ 
   document.tags.LI.fontSize = fontSizeOf.li;
   document.tags.UL.fontSize = fontSizeOf.ul;
   document.tags.OL.fontSize = fontSizeOf.ol;
   document.tags.DL.fontSize = fontSizeOf.dl;
   document.tags.DT.fontSize = fontSizeOf.dt;
   document.tags.DD.fontSize = fontSizeOf.dd;
   document.tags.BLOCKQUOTE.fontSize = fontSizeOf.blockquote;
   document.tags.TH.fontSize = fontSizeOf.th;
   document.tags.TD.fontSize = fontSizeOf.td;

   document.classes.titlepage.all.fontSize = fontSizeOf.titlepage;
   document.classes.small.all.fontSize = fontSizeOf.small;
   document.classes.medium.all.fontSize = fontSizeOf.medium;
   document.classes.large.all.fontSize = fontSizeOf.large;
   document.classes.footnote.all.fontSize = fontSizeOf.small;
// * Works only for Microsoft Internet Explorer
   document.classes.BODY.all.fontFamily = "Arial, Verdana, Helvetica";
	}
   return fontSizeOf
}

// Global variables speakerNotesMode and tutorialMode determines whether we are in:
// * speaker notes display mode (speaker mode text visible, all text in smaller fonts so speaker notes fit on screen)
// * tutorial mode (tutorial mode text visible, text in slightly larger fonts for online viewing)
// * normal mode (speaker mode text invisible because color is same as backgroundcolor, all text in large fonts 
//   appropriate for overhead display).

var speakerNotesMode = false
var tutorialMode = false

// Adjust font sizes downward in speakerNotes and tutorial modes.
var sizeMultiplier = 1.0                      // default
if (tutorialMode) sizeMultiplier = 0.79       // online viewing
if (speakerNotesMode) sizeMultiplier = 0.55   // speaker preparation with notes
var minFontSize = 4                          // smallest ever displayed

if (navigator.appName != "Microsoft Internet Explorer")   
	{

// Global variable fontSizeOf will store the per-element size data for the current screen size so that style
// sheets in individual HTML pages can retrieve and use this data. 

var fontSizeOf

// onLoad method 
function moveSpeakerNotes ()
{   if (speakerNotesMode && !tutorialMode && document.speakernotessection) 
    {   if (document.tutorialsection)
        {   document.speakernotessection.moveToAbsolute(document.tutorialsection.pageX, 
          document.tutorialsection.pageY)    }
        document.speakernotessection.visibility="visible"
	}
    }
}

// Workaround for Nav3.x bug in which JavaScript files with <SCRIPT LANGUAGE="JavaScript1.2" SRC=...> are
// loaded, even though they should be ignored. Make sure this code is only executed by 4.x and later.
if (parseInt(navigator.appVersion) > 3) {

var screenWidth = screen.width

/* 640x480 is 0.8 times the size of 800x600, so scale down by 20%. */
if (screenWidth < 700) {
       fontSizeOf = setFontSizes (18, 16, 14, 12, 10, 8, 10,  5,  5, 6,  6,  6,  6,  6,  6,  6,  6,  6,  6,  4, 6,  8, sizeMultiplier, minFontSize) }

/* 12" monitor of 800x600 pixels is the size which we consider "base"; 
   all other sizes are designed to scale so that their content will fit
   within an 800x600 pixel size area.  This is the pixel size used by 12"
   laptop monitors as well as many overhead display systems. */
else if (screenWidth < 900) {
     fontSizeOf = setFontSizes (20, 18, 16, 14, 12, 10, 12, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 6, 8, 10, sizeMultiplier, minFontSize) }
// (h1, h2, h3, h4, h5, h6, titlepage, p, li, ul, ol, dl, dt, dd, blockquote, th, td, pre, tt, small, medium, large, sizeMult, minOK
//    1    2    3    4    5    6         7       8  9  10 11 12 13 14       15          16 17  18  19   20        21         22
//  22   21  20  19  18 17       16     15 14 13 12 11 10  9         8            7   6    5    4     3          2           1
// (h1, h2, h3, h4, h5, h6, titlepage, p, li, ul, ol, dl, dt, dd, blockquote, th, td, pre, tt, small, medium, large, sizeMultiplier, minFontSize)

/* 17" monitor of 1024x768 pixels is 1.28 times larger than 12",
   so scale up by 28% to make sure HTML still fits on smaller page. */
else if (screenWidth < 1050) {
//                                              (h1, h2, h3, h4, h5, h6, titlepage, p, li,  ul,  ol,  dl,  dt, dd, blockquote, th,  td, pre, tt, small, medium, large, sizeMultiplier, minFontSize)
     fontSizeOf = setFontSizes (22, 20, 18, 16, 14, 12,       14,     9, 9, 10, 10, 10, 10, 10,         10,      10, 10, 10, 10,    8,         10,         12, sizeMultiplier, minFontSize) }
//   fontSizeOf = setFontSizes (22, 20, 18, 16, 14, 12,       6,     6, 6, 6, 6, 6, 6, 6,         6,      6, 6, 6, 6,    6,         6,         6,  1.00,  4) }

/* 20" monitor of 1280x1024 pixels is 1.7 times larger than 800x600,
   so scale up by 70% to make sure HTML still fits on smaller page. */
else if (screenWidth < 1300) {
     fontSizeOf = setFontSizes (40, 37, 34, 30, 27, 24, 27, 16, 18, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 10, 14, 16, sizeMultiplier, minFontSize) }

/* 21" monitor of 1600x1200 pixels is 2.0 times larger than 800x600,
   so scale up by 100% to make sure HTML still fits on smaller page. */
else {
     fontSizeOf = setFontSizes (48, 44, 40, 36, 32, 28, 32, 16, 20, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 12, 16, 22, sizeMultiplier, minFontSize) }

// properties which don't depend on current screen size

// global variables used to set text and background color
var presentationTextColor = "black"
var presentationBackgroundColor = "white"

if (navigator.appName != "Microsoft Internet Explorer")   
	{
document.tags.BODY.color = presentationTextColor
document.tags.BODY.backgroundColor = presentationBackgroundColor

if (speakerNotesMode) {     
   document.contextual(document.ids.speakernotessection, document.tags.H1).textDecoration = "underline"
   document.contextual(document.ids.speakernotessection, document.tags.H1).marginTop = "1em"
   self.onLoad = moveSpeakerNotes;
}

if (tutorialMode) {
// properties added for tutorial
// document.ids.tutorialsection.marginTop = "3em"
document.ids.tutorialsection.marginRight = "40px"
document.ids.tutorialsection.borderStyle = "solid"
document.ids.tutorialsection.borderColor = "gray"
document.ids.tutorialsection.borderWidths("2px")
document.ids.tutorialsection.paddings("1em")
}

document.tags.H1.fontWeight = "bold"

// enhance readability of source code by making it bold
document.tags.PRE.fontWeight = "bold"

document.classes.titlepage.all.fontWeight = "bold"
document.classes.titlepage.all.textAlign = "center"
document.classes.footnote.all.textAlign = "right"

// An example of defining classes to create a visual effect which can be used across many slides.  All elements which 
// have CLASS="dutchman" in their start tag will display in black text on a white background.
document.classes.dutchman.all.color = "black"
document.classes.dutchman.all.backgroundColor = "white"
document.classes.dutchman.all.fontFamily = "Arial, Verdana, Helvetica, sans-serife"

document.classes.dutchmanplus.all.color = "blue"
document.classes.dutchmanplus.all.backgroundColor = "yellow"
document.classes.dutchmanplus.all.fontFamily = "Arial, Verdana, Helvetica, sans-serife"

// Hack to keep backward compatibility with pages which have per-page style settings (setting inside a STYLE element
// in the page's HEAD) made using older version (1.0) of template. Set variable v1CompatibilityMode to true to use v1.0 
// pages with this version without having to update those per-page settings.

var v1CompatibilityMode = false
if (v1CompatibilityMode) {
var currentScreen = 0
var theFontSizes = new Array(1)
theFontSizes[currentScreen] = fontSizeOf
	}
}

} // end of file
