/*
** External JavaScript 'ozhug.js'
** This script is exclusively for The Huguenot Society of Australia website
**
** Author:	Ken Namihira
** Version:	2.0
** Last Update: 06 Feb 2003
*/

STD_WIDTH = 760		// standard available width (px)
STD_HEIGHT = 420	// standard available height (px)
STD_FONT_SIZE = 12	// standard font size at standard available window size above (px)

var availHeight		// available window height
var availWidth		// available window width

/* obtaining available window size */
function visibleArea () {
  if (document.all) {
    availHeight = document.body.clientHeight	// IE
    availWidth = document.body.clientWidth
  }
  else {
    if (document.getElementById) {
      availHeight = top.window.innerHeight	// Netscape 6+
      availWidth = top.window.innerWidth
    }
    else {
      availHeight = STD_HEIGHT			// Netscape 4.x (fixed)
      availWidth = STD_WIDTH
    }
  }
}

/* property definitions for an object of flexible sized image */
/* inputs:	originalWidth	- original object width (px)
		originalHeight	- original object height (px)
		dispWidthPrp	- proportion of display area to available window width (%)
		dispHeightPrp	- proportion of display area to available window height (%)
		magnitude	- proportion of actual object size to display area (%)		*/
function objLiqSize (originalWidth, originalHeight, dispWidthPrp, dispHeightPrp, magnitude) {
  this.originalWidth = originalWidth
  this.originalHeight = originalHeight
  this.dispWidthPrp = dispWidthPrp
  this.dispHeightPrp = dispHeightPrp
  this.magnitude = magnitude
  this.getSize ()	// call a method to calculate the object size
}

/* calculating an object size */
/* outputs: 	resizedWidth	- actual display width of the object (px)
		resizedHeight	- actual display height of the object (px) */
objLiqSize.prototype.getSize = function () {
  visibleArea ()
  dispWidth = availWidth * this.dispWidthPrp / 100
  dispHeight = availHeight * this.dispHeightPrp / 100
  widthPrption = dispWidth / this.originalWidth
  heightPrption = dispHeight / this.originalHeight
  smallerPrption = (heightPrption > widthPrption)? widthPrption : heightPrption
  this.resizedWidth = Math.floor (this.originalWidth * smallerPrption * this.magnitude / 100)
  this.resizedHeight = Math.floor (this.originalHeight * smallerPrption * this.magnitude / 100)
}

/* writing html tags for making an layer contains an image */
/* inputs:	id	- layer ID
		href	- URL for image source
		width	- image width (px)
		height	- image height (px)
		imgAlt	- alternate text for the image
		imgName	- image ID
		aHref	- URL for the link put on the image */
function dispImage (id, href, width, height, imgAlt, imgName, aHref) {
  document.write ('<div id=' + id + '>')
  if (aHref != "") {
    document.write ('<a href=' + aHref + '>')
  }
  document.write ('<img src=' + href + ' border=0 width=' + width + ' height=' + height + ' alt=' + imgAlt + ' name=' + imgName + '>')
  if (aHref != "") {
    document.write ('</a>')
  }
  document.write ('</div>')
}

/* adding a new style rule onto a tag */
/* inputs:	selector - tag name
		property - property that must be set
		value - value for the property		*/
function addStyleToTag (selector, property, value) {
  if (document.all) {
    document.all.tags(selector).item(0).style[property] = value			// IE
  }
  else {
    if (document.getElementById) {
      document.getElementsByTagName(selector).item(0).style[property] = value	// NS6+
    }
  }
}

/* setting basic font size depends on the available window size */
function basicFontSizeSet () {
  if (document.layers) {
    return 0
  }
  visibleArea ()
  widthPrption = availWidth / STD_WIDTH
  heightPrption = availHeight / STD_HEIGHT
  fontSize = (heightPrption > widthPrption)? widthPrption * STD_FONT_SIZE : heightPrption * STD_FONT_SIZE

  valueStr = fontSize + "px"
  addStyleToTag ('body', 'fontSize', valueStr)
}

/* property definitions for an object of a layer */
/* input:	objID - layer ID */
function objLayerSize (objID) {
  this.objID = objID
  this.getSize ()	// calling a method to obtain actual layer size
}

/* obtaining actual layer size */
/* outputs:	layerWidth - layer width (px)
		layerHeight - layer height (px) */
objLayerSize.prototype.getSize = function () {
  this.layerDom = findDOM (this.objID, 0)

  if (document.all) {
    this.layerWidth = this.layerDom.clientWidth		// IE
    this.layerHeight = this.layerDom.clientHeight
  }
  else {
    if (document.getElementById) {
      this.layerWidth = this.layerDom.offsetWidth	// NS6+
      this.layerHeight = this.layerDom.offsetHeight
    }
    else {
      this.layerWidth = this.layerDom.clip.width	// NS4
      this.layerHeight = this.layerDom.clip.height
    }
  }
}

/* layer positioning */
/* inputs:	layerDom - DOM
		x - horizontal distance from top left corner (px)
		y - vertical distance from top left corner (px)		*/
function moveLayer (layerDom, x, y) {
  if (document.all) {
    layerDom.style.pixelLeft = x	// IE
    layerDom.style.pixelTop = y
  }
  else {
    if (document.getElementById) {
      layerDom.style.left = x		// NS6+
      layerDom.style.top = y
    }
    else {
      layerDom.left = x			// NS4
      layerDom.top = y
    }
  }
}

/* calculating exact position for a layer */
/* inputs:	layerid - layer ID
		areaTopPrption - proportion of positioning area top to available window size (%)
		areaLeftPrption - proportion of positioning area left to available window size (%)
		areaWidthPrption - proportion of positioning area width to available window size (%)
		areaHeightPrption - proportion of positioning area height to available window size (%)
		hAlign - holizontal alignment withing the positioning area
		vAlign - vertical alignment withing the positioning area				*/
function relocate (layerid, areaTopPrption, areaLeftPrption, areaWidthPrption, areaHeightPrption, hAlign, vAlign) {
  if (document.layers && layerid != 'photo1' && layerid != 'photo2') {
    return 0
  }
  visibleArea ()
  areaTop = availHeight * areaTopPrption / 100
  areaLeft = availWidth * areaLeftPrption / 100
  areaWidth = availWidth * areaWidthPrption / 100
  areaHeight = availHeight * areaHeightPrption / 100

  targetLayer = new objLayerSize (layerid)

  if (vAlign == "middle") {
    posTop = Math.floor (areaTop + (areaHeight - targetLayer.layerHeight) / 2)
  }
  else {
    if (vAlign == "bottom") {
      posTop = Math.floor (areaTop + areaHeight - targetLayer.layerHeight)
    }
    else {
      posTop = areaTop
    }
  }

  if (hAlign == "center") {
    posLeft = Math.floor (areaLeft + (areaWidth - targetLayer.layerWidth) / 2)
  }
  else {
    if (hAlign == "right") {
      posLeft = Math.floor (areaLeft + areaWidth - targetLayer.layerWidth)
    }
    else {
      posLeft = areaLeft
    }
  }

  if (posTop < areaTop) posTop = areaTop	// forcing a layer not to be pushed out area top
  if (document.layers && layerid == 'copyr') {
    posLeft = 0		// special positioning only for NS4
    posTop = availHeight * 1.5
  }

  moveLayer (targetLayer.layerDom, posLeft, posTop)
}

/* controlling visibility of a layer */
/* inputs:	layerDom - DOM with style
		status - visibility status */
function visibilityControl (layerDom, status) {
  if (document.layers) {
    layerDom.visibility = (status == 'visible')? 'show' : 'hide'	// NS4
  }

  layerDom.visibility = status						// IE & NS6+
}


/* controlling visibility of a layer */
/* inputs:	objectID - layer ID
		status - visibility status */
function helpButton (objectID, status) {
  layerDom = findDOM (objectID, 1)

  visibilityControl (layerDom, status)
}

function refresh () {
  location.reload ()
}

function dispHintBtn () {
  if (document.layers) {
    return 0
  }
  document.write ("<a href=javascript:nop() onMouseover=helpButton('navHelpCont','visible') onMouseout=helpButton('navHelpCont','hidden')><img src=images/hint.gif border=0 alt=HINT></a>")
}

/* countermeasure for W3C validation error */
function hugRingLink () {
  document.write ("HUGUENOT RING<br><span class=fontSize75p>[ <a href=http://P.webring.com/wrman?ring=huguenot&addsite target=_top>Join Now</a> | <a href=http://P.webring.com/hub?ring=huguenot&id=111&hub target=_top>Ring Hub</a> | <a href=http://P.webring.com/go?ring=huguenot&id=111&random target=_top>Random</a> | <b><a href=http://P.webring.com/go?ring=huguenot&id=111&prev target=_top>&lt;&lt; Prev</a></b> | <b><a href=http://P.webring.com/go?ring=huguenot&id=111&next target=_top>Next &gt;&gt;</a></b> ]</span></div>")
}

/* no operation */
function nop () {}

/* auto screen refresh when resizing */
onresize = refresh

/* stylesheet exchange */
if (!document.layers) {
  linkObj = document.getElementsByTagName ('link')
  linkObj[1].disabled = true
  linkObj[0].disabled = false
}

