// generic stuff

// **************************************************
/* ***********************************************************
Example 4-5 (DHTMLapi.js)
"Dynamic HTML:The Definitive Reference"
by Danny Goodman
Published by O'Reilly & Associates  ISBN 1-56592-494-0
http://www.oreilly.com
Copyright 1998 Danny Goodman.  All Rights Reserved.
************************************************************ */
// DHTMLapi.js custom API for cross-platform
// object positioning by Danny Goodman (http://www.dannyg.com)

// Global variables
var isNav, isIE
var coll = ""
var styleObj = ""
if (parseInt(navigator.appVersion) >= 4) {
  if (navigator.appName == "Netscape") {
    isNav = true
  } else {
    isIE = true
    coll = "all."
    styleObj = ".style"
  }
}

// Convert object name string or object reference
// into a valid object reference
function getObject(obj) {
  var theObj
  if (typeof obj == "string") {
    theObj = eval("document." + coll + obj + styleObj)
  } else {
    theObj = obj
  }
  return theObj
}

// Positioning an object at a specific pixel coordinate
function shiftTo(obj, x, y) {
  var theObj = getObject(obj)
  if (isNav) {
    theObj.moveTo(x,y)
  } else {
    theObj.pixelLeft = x
    theObj.pixelTop = y
  }
}

// Moving an object by x and/or y pixels
function shiftBy(obj, deltaX, deltaY) {
  var theObj = getObject(obj)
  if (isNav) {
    theObj.moveBy(deltaX, deltaY)
  } else {
    theObj.pixelLeft += deltaX
    theObj.pixelTop += deltaY
  }
}

// Setting the z-order of an object
function setZIndex(obj, zOrder) {
  var theObj = getObject(obj)
  theObj.zIndex = zOrder
}

// Setting the background color of an object
function setBGColor(obj, color) {
  var theObj = getObject(obj)
  if (isNav) {
    theObj.bgColor = color
  } else {
    theObj.backgroundColor = color
  }
}

// Setting the visibility of an object to visible
function show(obj) {
  var theObj = getObject(obj)
  theObj.visibility = "visible"
}

// Setting the visibility of an object to hidden
function hide(obj) {
  var theObj = getObject(obj)
  theObj.visibility = "hidden"
}

// Retrieving the x coordinate of a positionable object
function getObjectLeft(obj)  {
  var theObj = getObject(obj)
  if (isNav) {
    return theObj.left
  } else {
    return theObj.pixelLeft
  }
}

// Retrieving the y coordinate of a positionable object
function getObjectTop(obj)  {
  var theObj = getObject(obj)
  if (isNav) {
    return theObj.top
  } else {
    return theObj.pixelTop
  }
}

// Utility function returns the available content width space in browser window
function getInsideWindowWidth(){
  if (isNav) {
    return window.innerWidth
  } else {
    return document.body.clientWidth
  }
}

// Utility function returns the available content height space in browser window
function getInsideWindowHeight() {
  if (isNav) {
    return window.innerHeight
  } else {
//    if(document.body.clientHeight>0) { return document.body.clientHeight }
    return document.documentElement.clientHeight
  }
}


// ***********************************************************
// from http://developer.apple.com/internet/webcontent/styles.html


// Copyright © 2001 by Apple Computer, Inc., All Rights Reserved.
//
// You may incorporate this Apple sample code into your own code
// without restriction. This Apple sample code has been provided "AS IS"
// and the responsibility for its operation is yours. You may redistribute
// this code, but you are not permitted to redistribute it as
// "Apple sample code" after having made changes.

// ugly workaround for missing support for selectorText in Netscape6/Mozilla
// call onLoad() or before you need to do anything you would have otherwise used
// selectorText for.
var ugly_selectorText_workaround_flag = false;
var allStyleRules;
// code developed using the following workaround (CVS v1.15) as an example.
// http://lxr.mozilla.org/seamonkey/source/extensions/xmlterm/ui/content/XMLTermCommands.js
function ugly_selectorText_workaround() {
  if((navigator.userAgent.indexOf("Gecko") == -1) ||
     (ugly_selectorText_workaround_flag)) {
    return; // we've already been here or shouldn't be here
  }
  var styleElements = document.getElementsByTagName("style");

  for(var i = 0; i < styleElements.length; i++) {
    var styleText = styleElements[i].firstChild.data;
    // this should be using match(/\b[\w-.]+(?=\s*\{)/g but ?= causes an
    // error in IE5, so we include the open brace and then strip it
    allStyleRules = styleText.match(/\b[\w-.]+(\s*\{)/g);
  }

  for(var i = 0; i < allStyleRules.length; i++) {
    // probably insufficient for people who like random gobs of
    // whitespace in their styles
    allStyleRules[i] = allStyleRules[i].substr(0, (allStyleRules[i].length - 2));
  }
  ugly_selectorText_workaround_flag = true;
}


// setStyleById: given an element id, style property and
// value, apply the style.
// args:
//  i - element id
//  p - property
//  v - value
//
function setStyleById(i, p, v) {
  var n = document.getElementById(i);
  n.style[p] = v;
}

// getStyleById: given an element ID and style property
// return the current setting for that property, or null.
// args:
//  i - element id
//  p - property
function getStyleById(i, p) {
  var n = document.getElementById(i);
  var s = eval("n.style." + p);

  // try inline
  if((s != "") && (s != null)) {
    return s;
  }

  // try currentStyle
  if(n.currentStyle) {
    var s = eval("n.currentStyle." + p);
    if((s != "") && (s != null)) {
      return s;
    }
  }

  // try styleSheets
  var sheets = document.styleSheets;
  if(sheets.length > 0) {
    // loop over each sheet
    for(var x = 0; x < sheets.length; x++) {
      // grab stylesheet rules
      var rules = sheets[x].cssRules;
      if(rules.length > 0) {
        // check each rule
        for(var y = 0; y < rules.length; y++) {
          var z = rules[y].style;
          // selectorText broken in NS 6/Mozilla: see
          // http://bugzilla.mozilla.org/show_bug.cgi?id=51944
          ugly_selectorText_workaround();
          if(allStyleRules) {
            if(allStyleRules[y] == i) {
              return z[p];
            }
          } else {
            // use the native selectorText and style stuff
            if(((z[p] != "") && (z[p] != null)) ||
               (rules[y].selectorText == i)) {
              return z[p];
            }
          }
        }
      }
    }
  }
  return null;
}

// setStyleByClass: given an element type and a class selector,
// style property and value, apply the style.
// args:
//  t - type of tag to check for (e.g., SPAN)
//  c - class name
//  p - CSS property
//  v - value
var ie = (document.all) ? true : false;

function setStyleByClass(t,c,p,v){
  var elements;
  if(t == '*') {
    // '*' not supported by IE/Win 5.5 and below
    elements = (ie) ? document.all : document.getElementsByTagName('*');
  } else {
    elements = document.getElementsByTagName(t);
  }
  for(var i = 0; i < elements.length; i++){
    var node = elements.item(i);
    for(var j = 0; j < node.attributes.length; j++) {
      if(node.attributes.item(j).nodeName == 'class') {
        if(node.attributes.item(j).nodeValue == c) {
          eval('node.style.' + p + " = '" +v + "'");
        }
      }
    }
  }
}

// getStyleByClass: given an element type, a class selector and a property,
// return the value of the property for that element type.
// args:
//  t - element type
//  c - class identifier
//  p - CSS property
function getStyleByClass(t, c, p) {
  // first loop over elements, because if they've been modified they
  // will contain style data more recent than that in the stylesheet
  var elements;
  if(t == '*') {
    // '*' not supported by IE/Win 5.5 and below
    elements = (ie) ? document.all : document.getElementsByTagName('*');
  } else {
    elements = document.getElementsByTagName(t);
  }
  for(var i = 0; i < elements.length; i++){
    var node = elements.item(i);
    for(var j = 0; j < node.attributes.length; j++) {
      if(node.attributes.item(j).nodeName == 'class') {
        if(node.attributes.item(j).nodeValue == c) {
          var theStyle = eval('node.style.' + p);
          if((theStyle != "") && (theStyle != null)) {
            return theStyle;
          }
        }
      }
    }
  }
  // if we got here it's because we didn't find anything
  // try styleSheets
  var sheets = document.styleSheets;
  if(sheets.length > 0) {
    // loop over each sheet
    for(var x = 0; x < sheets.length; x++) {
      // grab stylesheet rules
      var rules = sheets[x].cssRules;
      if(rules.length > 0) {
        // check each rule
        for(var y = 0; y < rules.length; y++) {
          var z = rules[y].style;
          // selectorText broken in NS 6/Mozilla: see
          // http://bugzilla.mozilla.org/show_bug.cgi?id=51944
          ugly_selectorText_workaround();
          if(allStyleRules) {
            if((allStyleRules[y] == c) ||
               (allStyleRules[y] == (t + "." + c))) {
              return z[p];
            }
          } else {
            // use the native selectorText and style stuff
            if(((z[p] != "") && (z[p] != null)) &&
               ((rules[y].selectorText == c) ||
                (rules[y].selectorText == (t + "." + c)))) {
              return z[p];
            }
          }
        }
      }
    }
  }

  return null;
}

// setStyleByTag: given an element type, style property and
// value, and whether the property should override inline styles or
// just global stylesheet preferences, apply the style.
// args:
//  e - element type or id
//  p - property
//  v - value
//  g - boolean 0: modify global only; 1: modify all elements in document
function setStyleByTag(e, p, v, g) {
  if(g) {
    var elements = document.getElementsByTagName(e);
    for(var i = 0; i < elements.length; i++) {
      elements.item(i).style[p] = v;
    }
  } else {
    var sheets = document.styleSheets;
    if(sheets.length > 0) {
      for(var i = 0; i < sheets.length; i++) {
        var rules = sheets[i].cssRules;
        if(rules.length > 0) {
          for(var j = 0; j < rules.length; j++) {
            var s = rules[j].style;
            // selectorText broken in NS 6/Mozilla: see
            // http://bugzilla.mozilla.org/show_bug.cgi?id=51944
            ugly_selectorText_workaround();
            if(allStyleRules) {
              if(allStyleRules[j] == e) {
                s[p] = v;
              }
            } else {
              // use the native selectorText and style stuff
              if(((s[p] != "") && (s[p] != null)) &&
                 (rules[j].selectorText == e)) {
                s[p] = v;
              }
            }

          }
        }
      }
    }
  }
}

// getStyleByTag: given an element type and style property, return
// the property's value
// args:
//  e - element type
//  p - property
function getStyleByTag(e, p) {
  var sheets = document.styleSheets;
  if(sheets.length > 0) {
    for(var i = 0; i < sheets.length; i++) {
      var rules = sheets[i].cssRules;
      if(rules.length > 0) {
        for(var j = 0; j < rules.length; j++) {
          var s = rules[j].style;
          // selectorText broken in NS 6/Mozilla: see
          // http://bugzilla.mozilla.org/show_bug.cgi?id=51944
          ugly_selectorText_workaround();
          if(allStyleRules) {
            if(allStyleRules[j] == e) {
              return s[p];
            }
          } else {
            // use the native selectorText and style stuff
            if(((s[p] != "") && (s[p] != null)) &&
               (rules[j].selectorText == e)) {
              return s[p];
            }
          }

        }
      }
    }
  }

  // if we don't find any style sheets, return the value for the first
  // element of this type we encounter without a CLASS or STYLE attribute
  var elements = document.getElementsByTagName(e);
  var sawClassOrStyleAttribute = false;
  for(var i = 0; i < elements.length; i++) {
    var node = elements.item(i);
    for(var j = 0; j < node.attributes.length; j++) {
      if((node.attributes.item(j).nodeName == 'class') ||
         (node.attributes.item(j).nodeName == 'style')){
         sawClassOrStyleAttribute = true;
      }
    }
    if(! sawClassOrStyleAttribute) {
      return elements.item(i).style[p];
    }
  }
}



function getHeightOfId(ID){
  if(arguments.length!=1)alert("Wrong number of arguments to getHeightOfID()");
  var ns6=document.getElementById&&!document.all
  var ie=document.all

  if((!ie)&&(!ns6)){
    var AlertStr="Alert you appear to be running an outdated browser. ";
    AlertStr=AlertStr+"Please upgrade to a more recent browser. ";
    AlertStr=AlertStr+"Some things on this site will not work properly with your current browser.";
    alert(AlertStr);
  }

  if(ns6){
    return(document.getElementById(ID).offsetHeight);
  }

  if(ie){
    var retval=eval("document.all." + ID + ".clientHeight");
    if(retval==0)retval=(eval("document.all." + ID + ".offsetHeight"));
    return(retval);
  }

  return(50);
}


// function to force very soft reloading of pages when browser resizes

function onResizeProc(){history.go(0);}



// **************************************************

// baroque week javascript

var quotes=new Array();

quotes[0]="";
quotes[0]+="<div class=quote>";
quotes[0]+="  My heartfelt thanks to you";
quotes[0]+="  for organising such an inspiring week";
quotes[0]+="  <div class=attrib>";
quotes[0]+="    first-time attender";
quotes[0]+="  </div>";
quotes[0]+="</div>";


quotes[1]="";
quotes[1]+="<div class=quote>";
quotes[1]+="  I had an amazing, wonderful,";
quotes[1]+="  fantastic time on your course.";
quotes[1]+="  Thank you so much.";
quotes[1]+="  <div class=attrib>";
quotes[1]+="    first-time attender";
quotes[1]+="  </div>";
quotes[1]+="</div>";


quotes[2]="";
quotes[2]+="<div class=quote>";
quotes[2]+="  What a wonderful week!";
quotes[2]+="  It was a priviledge being part of such a lovely event";
quotes[2]+="  <div class=attrib>";
quotes[2]+="    RL";
quotes[2]+="  </div>";
quotes[2]+="</div>";

quotes[3]="";
quotes[3]+="<div class=quote>";
quotes[3]+="  What a fabulous week this year.";
quotes[3]+="  I know people always say &#147;the best yet&#148;,";
quotes[3]+="  but for me it really seemed so.";
quotes[3]+="  <div class=attrib>";
quotes[3]+="    AW";
quotes[3]+="  </div>";
quotes[3]+="</div>";

quotes[4]="";
quotes[4]+="<div class=quote>";
quotes[4]+="  I am so lucky to have found your wonderful";
quotes[4]+="  course and met such great people.";
quotes[4]+="  <div class=attrib>";
quotes[4]+="    KE";
quotes[4]+="  </div>";
quotes[4]+="</div>";

quotes[5]="";
quotes[5]+="<div class=quote>";
quotes[5]+="  Thank you for all your hard work in Oxford.";
quotes[5]+="  Shame that I didn&#146;t come on it earlier.";
quotes[5]+="  <div class=attrib>";
quotes[5]+="    first-time attender";
quotes[5]+="  </div>";
quotes[5]+="</div>";

quotes[6]="";
quotes[6]+="<div class=quote>";
quotes[6]+="  I&#146;m so glad I tried it out and now";
quotes[6]+="  can&#146;t imagine a summer without it.";
quotes[6]+="  <div class=attrib>";
quotes[6]+="    first-time attender";
quotes[6]+="  </div>";
quotes[6]+="</div>";



var qinds=new Array(4);

function set_qinds(){
  var date=new Date();
  var rval=Math.round(date.getSeconds()*Math.random());
  var i;
  for(i=0;i<4;i++){
    qinds[i]=(rval+i)%quotes.length;
  }
}


function quote(quotes,num){
  document.write(rval + " " + quotes[rval]);
}


var bstr0="p.b.c";
var bstr1="olli";
var bstr2="er@g";
var bstr3="oog";
var bstr4="lema";
var bstr5="il.";
var bstr6="com";

function blat(){
  document.write("<a class=inpage href='mailto:" + bstr0 + bstr1 + bstr2 + bstr3 + bstr4 + bstr5 + bstr6 + "'>");
  document.write(bstr0 + bstr1 + bstr2 + bstr3 + bstr4 + bstr5 + bstr6 + "</a>");
}




// stuff for photos round edge

// arrays to hold image strings


var img_landscape=new Array(
  "<img src='sideimg/rscn5826-ls.jpg' width=220 height=165>",
  "<img src='sideimg/rscn5824-ls.jpg' width=220 height=165>",
  "<img src='sideimg/rscn5823-ls.jpg' width=220 height=165>",
  "<img src='sideimg/dscn5797-ls.jpg' width=220 height=165>",
  "<img src='sideimg/dscn5788-ls.jpg' width=220 height=165>",
  "<img src='sideimg/dscn5765-ls.jpg' width=220 height=165>",
  "<img src='sideimg/dscn5763-ls.jpg' width=220 height=165>",
  "<img src='sideimg/dscn5755-ls.jpg' width=220 height=165>",
  "<img src='sideimg/dscn5743-ls.jpg' width=220 height=165>",
  "<img src='sideimg/dscn5741-ls.jpg' width=220 height=165>",
  "<img src='sideimg/dscn5719-ls.jpg' width=220 height=165>",
  "<img src='sideimg/dscn5706-ls.jpg' width=220 height=165>",
  "<img src='sideimg/dscn5690-ls.jpg' width=220 height=165>",
  "<img src='sideimg/dscn5678-ls.jpg' width=220 height=165>"
);

var indices_landscape=new Array(2);

var img_portrait=new Array(
  "<img src='sideimg/dscn5663-po.jpg' width=180 height=240>",
  "<img src='sideimg/dscn5665-po.jpg' width=180 height=240>",
  "<img src='sideimg/dscn5669-po.jpg' width=180 height=240>",
  "<img src='sideimg/dscn5671-po.jpg' width=180 height=240>",
  "<img src='sideimg/dscn5675-po.jpg' width=180 height=240>",
  "<img src='sideimg/dscn5676-po.jpg' width=180 height=240>",
  "<img src='sideimg/dscn5683-po.jpg' width=180 height=240>",
  "<img src='sideimg/dscn5687-po.jpg' width=180 height=240>",
  "<img src='sideimg/dscn5700-po.jpg' width=180 height=240>",
  "<img src='sideimg/dscn5713-po.jpg' width=180 height=240>",
  "<img src='sideimg/dscn5735-po.jpg' width=180 height=240>",
  "<img src='sideimg/dscn5754-po.jpg' width=180 height=240>",
  "<img src='sideimg/dscn5762-po.jpg' width=180 height=240>",
  "<img src='sideimg/dscn5780-po.jpg' width=180 height=240>",
  "<img src='sideimg/dscn5764-po.jpg' width=180 height=240>"
);

var indices_portrait=new Array(2);



var portrait_indval;
var landscape_indval;

function setup_photos(){
  var TimeNow=new Date();
  portrait_indval=(Math.round(TimeNow.getSeconds()*Math.random()))%(img_portrait.length-indices_portrait.length);

  landscape_indval=(Math.round(TimeNow.getSeconds()*Math.random()))%(img_landscape.length-indices_landscape.length);

  indices_portrait[0]=img_portrait[portrait_indval];
  indices_portrait[1]=img_portrait[portrait_indval+1];

  indices_landscape[0]=img_landscape[landscape_indval];
  indices_landscape[1]=img_landscape[landscape_indval+1];
}



// stuff for displaying libarary

var librarywin=null;
//alert("hello");
function openlib(url){
  var openwidth=700;
  var openheight=950;
  var args="height=" + openheight + ",width=" + openwidth + ",screenX=0,screenY=0,location=no,left=0,top=0,resizable=yes,status=no,toolbar=no,scrollbars=yes";
   if(librarywin!=null)librarywin.close();
   librarywin=open("","librarywin",args);
   var librarystr="";
   librarystr+="<html>";
   librarystr+="<head><link rel=stylesheet href='main.css' type=text/css></head>";
   librarystr+="<body>";
   librarystr+="<center>";
   librarystr+="<img src='library/" + url + "'>";
   librarystr+="<div class=caption><a href='javascript:self.close();'>click here to close</a></div>";
   librarystr+="</center>";
   librarystr+="</body>";
   librarystr+="</html>";
   librarywin.document.write(librarystr);
}
 
//alert("world");
 

