// Variables required for rollover images
var arrowRed = new Image;
var arrowBlue = new Image;

// Function to set up image array;
function setImages () {
  var undefined;
  if (document.getElementById != undefined && document.images != undefined) {
    arrowRed.src = 'images/redarrow.gif';
    arrowBlue.src = 'images/bluearrow.gif';
  }
}

// Function to swap an image
function swapImage (arrow) {
  var undefined;
  if (document.getElementById != undefined && document.images != undefined) {
    if (document.getElementById(arrow).src == arrowRed.src) 
      document.getElementById(arrow).src = arrowBlue.src;
    else 
      document.getElementById(arrow).src = arrowRed.src;
  }
}

// Used to set the cookie counter
function setCounter () {
  var allcookies = document.cookie;
  if (allcookies.indexOf("caving") == -1) {
    document.cookie = "caving=0";
  };
}

// Routine to display date modified message.
function datemodified () {
  var ModDate;
  ModDate = new Date (document.lastModified); 
  document.write ("Page last updated: " + ModDate.toLocaleDateString());
}

// Routine to display copyright notice on printed web pages
function displayURL() { 
  var today = new Date();
  document.write ("Printed from: " + document.URL + " on " + today.toLocaleDateString());
}

function openPopup (imageURL, caption) {

/*
This routine creates a pop-up window, and ensures that it takes focus. It is 
intended to be called from an anchor tag. The new window will resize itself to 
the optimum size, so we make it as large as the largest required window to
overcome bugs in various manifestations of various browser
  
Author:   John Gardner
Written:  8th November 2003
Updated:  27th January 2004

Calling sequence: <a href="a.jpg" onClick="return openLargeImage('a.jpg','Caption');">

The first parameter is the URL of the image to be opened, and the second 
parameter is the caption for the image which is displayed in the window title
and in the alt property of the image tag.

Note that the calling sequence will simply open the image in the main window if
JavaScript isn't enabled.
  
*/

  // Constants - change these to suit your requirements

  var windowTop = 100;                // Top position of popup
  var windowLeft = 100                // Left position of popup
  var defaultWidth = 730;             // Default width (for browsers that cannot resize)
  var defaultHeight = 532;            // Default height (for browsers that cannot resize)
  var onLoseFocusExit = true;         // Set if window to exit when it loses focus

  // Set up the window open options
  var Options = "width=" + defaultWidth + ",height=" + defaultHeight + ",top=" + windowTop + ",left=" + windowLeft + ",resizable"
  
  // Now write the HTML markup to the new window, ensuring that we insert the 
  // parameter URL of the image and the parameter description of the image in 
  // the right place.
  var myScript = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n" +
    "<html>\n" + 
    "<head>\n" + 
    "<title>" + caption + "\</title>\n" +
    "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">\n" +
    "<meta http-equiv=\"Content-Language\" content=\"en-gb\">\n" +
    "<script language=\"JavaScript\" type=\"text/javascript\">\n" +
    "function resizewindow () {\n" +
    "  var width = document.myimage.width;\n" + 
    "  var height = document.myimage.height;\n";
  
  // Opera needs a frig factor for the size of the window
  if (navigator.appName.indexOf("Opera") != -1) {
    myScript = myScript +  "  window.resizeTo (width+12, height+31);\n"
  }
  
  // We can use the internal window height and width for Netscape type browsers
  else if (navigator.appName.indexOf("Netscape") != -1 ) { 
    myScript = myScript +  "  window.innerHeight = height;\n  window.innerWidth = width;\n" 
  }
  
  // Microsoft needs yet a different frig factor
  else if (navigator.appName.indexOf("Microsoft") != -1) { 
    myScript = myScript + "  window.resizeTo (width+11, height+31);\n" 
  }
  
  // Assume a frig factor for any other browsers
  else {
    myScript = myScript + "  window.resizeTo (width+14, height+34);\n"
  }
      
  myScript = myScript + "}\n" + "window.onload = resizewindow;\n" +
    "</script>\n</head>\n" + "<body ";
    
  // If the window is required to close when it loses focus.
  if (onLoseFocusExit) {myScript = myScript + "onblur=\"self.close()\" ";}
    
  myScript = myScript + "style=\"margin: 0px; padding: 0px;\">\n" +
    "<img src=\"" + imageURL + "\" alt=\"" + caption + "\" title=\"" + caption + "\" name=\"myimage\">\n" + 
    "</body>\n" +  "</html>\n";
        
  // Create the popup window
  var imageWindow = window.open ("","imageWin",Options);
  imageWindow.document.write (myScript)
  imageWindow.document.close ();
  if (window.focus) imageWindow.focus();
  return false;
}

// Breaks out of frames
function frame_breaker() {

  if (top.location != self.location) {
    top.location.replace(self.location);
  }
}

// Display an appropriate fresh random quotation every ten seconds
function GetQuote (strings) {

  var RandomNumber = LastUsed;
  while (RandomNumber == LastUsed) {
    RandomNumber = Math.floor (Math.random ()* strings.length);
  }
  LastUsed = RandomNumber;
  document.getElementById('introtext').firstChild.nodeValue = strings[RandomNumber];
  document.getElementById('introtext').style.visibility = "visible";
  timerid = window.setTimeout ('EmptyQuote()',displayTime);
}

// Followed by the specified period of silence
function EmptyQuote () {
 
  document.getElementById('introtext').style.visibility = "hidden";
  timerid = window.setTimeout (RoutineCall,pauseTime);
}

// Called when the user clicks on the quote
function NextQuote (){
	window.clearTimeout(timerid);
	EmptyQuote(pauseTime);
}

// See which group of quotes we should display. It looks at the title.
function GetQuoteGroup() {
  
  switch (document.title)  {
    case 'Braemoor: Selected Caving Routes in the Yorkshire Dales':
	    RoutineCall='GetQuote(OtherQuotes);';
		  break;
  	case 'Braemoor: Index of Caving Articles':
	  	RoutineCall='GetQuote(OtherQuotes);';
			break;
		case 'Braemoor: Caving Copyright Notice':
	  	RoutineCall='GetQuote(CopyQuotes);';
			break;
	  case 'Braemoor: Links to Relevant Caving Web Sites':
	    RoutineCall='GetQuote(WebQuotes);';
		  break;
	  default:
		  break;
  }
}

// Called when the page loads to establish what page we're on and start the 
// timeout sequence going if we're on a page that displays a quotation.
function initialiseQuotations () {
  GetQuoteGroup();  
  if (RoutineCall != '') {
    timerid = window.setTimeout (RoutineCall,1);
  }
}

// Called when the page loads (onload). 
function initialise () {
  setImages ();
  initialiseQuotations ();
}

// On error routine
function doNothing () {
  return true;
}

//  The following the code is executed on page entry
//  ================================================

// Turn off error reporting
window.onerror = doNothing;

// Break out of any external frame.
frame_breaker();

// Quotations for the index and directory, the links, and the copyright pages
// To add further quotes, simply push one on to the end of the appropriate list.

// Link page quotations
var WebQuotes = new Array ();
WebQuotes.push ('"O What a tangled web we weave" - Sir Walter Scott');
WebQuotes.push ('"Tis true, there\'s magic in the web of it" - Othello. Act IV Sc.iv');
WebQuotes.push ('"The web of our life is of a mingled yarn, good and ill together." - All\'s Well that Ends Well. Act IV Sc. iii');
WebQuotes.push ('"Whose deadly web ensnareth thee about?" - Richard III. Act I, Scene 3'); 
WebQuotes.push ('"If you have knowledge, let others light their candles in it." - Margaret Fuller'); 

// Index and Directory page quotations
var OtherQuotes = new Array ();
OtherQuotes.push ('"what I hear is the murmur / Of underground streams, what I see is a limestone landscape" - W.H Auden');
OtherQuotes.push ('"in hollow halls beneath the fells" - J.R.Tolkien');
OtherQuotes.push ('"A secret system of caves and conduits"  - W.H Auden');
OtherQuotes.push ('"Leaning out over / The dreadful precipice, / One contemptuous tree." - W.H Auden');
OtherQuotes.push ('"Half our days we pass in the shadow of the earth" - Sir Thomas Browne');
OtherQuotes.push ('"Through caverns measureless to man" - Samual Taylor Coleridge');
OtherQuotes.push ('"Sand-strewn caverns, cool and deep" - Matthew Arnold');
OtherQuotes.push ('"immeasurable halls, filled with an everlasting music of water that tinkles into pools" - J.R.Tolkien');
OtherQuotes.push ('"we should open up new ways, and display far chambers that are still dark, glimpsed only as a void beyond fissures in the rock" - J.R.Tolkien');
OtherQuotes.push ('"through its intricate tangle of rifts and chasms" - Mark Twain');
OtherQuotes.push ('"Deep was the cave; and downwards as it went / From the wide mouth, a rocky rough descent;" - Vergil');
OtherQuotes.push ('"Caves in the mountain, clefts in the wall, / My Father has to inspect them all!" - Ted Hughes'); 
OtherQuotes.push ('"There is nothing more powerful than this attraction toward the abyss" - Jules Verne'); 
OtherQuotes.push ('"It is a cavernous Earth of labyrinthine intricacy" - William Blake'); 
OtherQuotes.push ('"The truth of nature lieth in certain deep mines and caves." - Democritus'); 
OtherQuotes.push ('"The words which make up the human language are inadequate for those who venture into the depths of the earth." - Jules Verne'); 
OtherQuotes.push ('"De profundis clamavi ad te Domine" - Psalm 129'); 
OtherQuotes.push ('"The cave itself enters human awareness as soon as humans are aware of anything." - Walter Wright Arthen');
OtherQuotes.push ('"When I enter a cave, I go to the deep heart of the matter." - Walter Wright Arthen'); 
OtherQuotes.push ('"There is many a rich stone laid up in the bowels of the earth ... that never was seen, nor never shall be" - Joseph Hall');
OtherQuotes.push ('"It is a good thing ... to creep like worms into dark holes and caverns underground" - John Muir'); 
OtherQuotes.push ('"They wound this way and that, far down into the secret depths of the cave" - Mark Twain');
OtherQuotes.push ('"There is a deep, wide gulf, a chasm, and in that chasm is no place for any man" - Johnny Cash');
OtherQuotes.push ('"being practiced in maintaining himself on insubstantial ropes ... dancing even near abysses" - Friedrich Nietzsche');
OtherQuotes.push ('"The descent to Avernus is easy; ... but to retrace one\'s steps and return to the upper air, that is the toil, that the difficulty." - Virgil');
OtherQuotes.push ('"tortuous caverns, and bottomless holes with endless ropes hanging down into them" - Mark Twain');
OtherQuotes.push ('"This cavern is in our parish, and you have no right to be here at all" - Thomas Hardy');
OtherQuotes.push ('"...Und im Abgrund wohnt die Wahrheit. (...and truth lies in the abyss.)" - J.C. Von Schiller');
OtherQuotes.push ('"The best parts are underground." - Francis Bacon');
OtherQuotes.push ('"I came to the entrance of a great cavern... two emotions suddenly arose in me, ... fear of the threatening dark cave, desire to see whether there are any marvelous thing within"- Leonardo da Vinci');
OtherQuotes.push ('"The world underground offered an infinite field of activity" - Felix Nadar');
OtherQuotes.push ('"a tangled wilderness of narrow and lofty clefts and passages" - Mark Twain');
OtherQuotes.push ('"The door of the cavern was big enough to roll a hogshead in" - Mark Twain');
OtherQuotes.push ('"The cave you fear to enter holds the treasure you seek." - Joseph Campbell');
OtherQuotes.push ('"the awful gloom of this doomed cavern" - Seneca ');
OtherQuotes.push ('"a tangled wilderness of narrow and lofty clefts and passages" - Mark Twain');
OtherQuotes.push ('"It was an easy place to get lost in; anybody could do it - including the bats" - Mark Twain');
OtherQuotes.push ('"And they besought him that he would not command them to go out into the deep" - Luke 8:31');
OtherQuotes.push ('"Who shall descend into the deep?" - Romans 10:7');
OtherQuotes.push ('"And out of the cleft came swarming a loathsome mob" - Robert E. Howard');
OtherQuotes.push ('"Many caves in these hills ... are but doors to greater caves which lie beneath" - Robert E. Howard');
OtherQuotes.push ('"a network of subterranean corridors which honeycombed the hills" - Robert E. Howard');
OtherQuotes.push ('"A life in caves and holes, where the rays of the sun do not enter, may perhaps tend to longevity" - Francis Bacon');
OtherQuotes.push ('"Leave the halls and caverns deep" - J.R. Tolkein');
OtherQuotes.push ('"The nethermost caverns are not for the fathoming of eyes that see; for their marvels are strange and terrific" - J.P. Lovecraft');
OtherQuotes.push ('"The fall of dropping water wears away the Stone." - Lucretius');
OtherQuotes.push ('"When you get to the end of your rope, tie a knot and hang on" - Franklin D. Roosevelt');
OtherQuotes.push ('"If you stare into the Abyss long enough the Abyss stares back at you" - Friedrich Nietzsche');
OtherQuotes.push ('"No solitude is comparable to the bowels of the earth, no night so dark as the blackness underground." - Norbert Casteret');
OtherQuotes.push ('"...without thought of the abysses into which my daring was soon about to plunge me." - Jules Verne');
OtherQuotes.push ('"One just principle from the depths of a cave is more powerful than an army" - Jose Marti');
OtherQuotes.push ('"a grand wilderness of caverned hills and wide-reaching moors" - Harry Speight');
OtherQuotes.push ('"I believe there never was a boy yet who saw a hole in the ground, or a cave in a hill, or much more an underground passage, but longed incontinently to be into it and discover whither it led." J. Meade Falkner'); 

// Copyright page quotations
var CopyQuotes = new Array ();
CopyQuotes.push ('"And this they wrote that another man wrote" - Rudyard Kipling');
CopyQuotes.push ('"Take away from English authors their copyrights, and you would very soon take away from England her authors." - Trollope');
CopyQuotes.push ( '"I wonder what kind of world it is where anyone can sing anyone else\'s song." - Frank McCourt');
CopyQuotes.push ( '"Perish those who said our good things before we did." - Donatus');
CopyQuotes.push ('"Think not rashly to lay your thievish hands upon my works" - Albrect D\u00fcrer');
CopyQuotes.push ('"If you cannot protect what you own, you don\'t own anything." - Jack Valenti');

// Initialise global variables used for quotations code
var RoutineCall;                     // Hold routine name for timeout event
var LastUsed;                        // Used to hold id of the last used quote
var timerid;                         // Used for timeout events;
var pauseTime = 750;                 // Number of milliseconds between quotes
var displayTime = 10000;             // Number of milliseconds to display quotes