var htmlPathname = window.location.pathname;
var htmlId       = htmlPathname.replace(/^.*\//, "").replace(/\.html$/, "").replace(/[0-9]{3}$/, "XXX");

document.getElementsByTagName("html")[0].style.fontSize = calcFontSize();

if      ( htmlId === "biograph" || htmlId === "texts" || htmlId === "textXXX" || htmlId === "books" || htmlId === "bookXXX" ) {
  window.onresize = resize_height;
  window.onload   = resize_height;
}
else if ( htmlId === "indexXXX" ) {
  document.getElementsByTagName("html")[0].style.overflow = "auto";

  window.onresize = function() {
    if (document.getElementById("introText"))
      window.location.hash = "";
    else
      window.location.hash = window.location.hash;
  }

  window.onload   = function() {
    preloadalltexts();
    changetext('001');
    preloadallimages();

    var x          = parseFloat( calcFontSize() ) / 62.5;
    var correction = 268 * x;
    var divHeight  = f_clientHeight() < 500 * x? 250 * x: f_clientHeight() - correction;
    var linHeight  = .90 * divHeight;
    var imgHeight  = .90 * divHeight;
//    var aspectRatio = document.getElementById("image").width / document.getElementById("image").height;
//    var imgWidth = imgHeight * aspectRatio;
    
    document.getElementById("mainImg").style.height     = divHeight + "px";
    document.getElementById("mainImg").style.lineHeight = linHeight + "px";
    document.getElementById("image").style.maxHeight    = imgHeight + "px";

    if (document.getElementById("introText"))
      resize_height();
  }
}
else  {
}
// ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼
function resize_height() {
    var elementId, correction;

    if      ( htmlId === "biograph" ) {
      elementId  = "biographText"
      correction = 140 * parseFloat(calcFontSize()) / 62.5;
      document.getElementById("hdrmargin").style.height = (( f_clientHeight() - correction ) *  .03 ) + "px";
      document.getElementById(elementId).style.height   = (( f_clientHeight() - correction ) *  .94 ) + "px";
      document.getElementById("ftrmargin").style.height = (( f_clientHeight() - correction ) *  .03 ) + "px";
    }
    else if ( htmlId === "indexXXX" ) {
      elementId  = "introText"
      correction = 26 * parseFloat(calcFontSize()) / 62.5;
      document.getElementById(elementId).style.minHeight = (( f_clientHeight() - correction ) * 1.00 ) + "px";
    }
    else if ( htmlId === "texts"    ) {
      elementId  = "textsText";
      correction = 140 * parseFloat(calcFontSize()) / 62.5;
      document.getElementById("hdrmargin").style.height = (( f_clientHeight() - correction ) *  .03 ) + "px";
      document.getElementById(elementId).style.height   = (( f_clientHeight() - correction ) *  .94 ) + "px";
      document.getElementById("ftrmargin").style.height = (( f_clientHeight() - correction ) *  .03 ) + "px";
    }
    else if ( htmlId === "textXXX"  ) {
      elementId  = "textText";
      correction = 140 * parseFloat(calcFontSize()) / 62.5;
      document.getElementById("hdrmargin").style.height = (( f_clientHeight() - correction ) *  .03 ) + "px";
      document.getElementById(elementId).style.height   = (( f_clientHeight() - correction ) *  .94 ) + "px";
      document.getElementById("ftrmargin").style.height = (( f_clientHeight() - correction ) *  .03 ) + "px";
    }
    else if ( htmlId === "books"    ) {
      elementId  = "booksText";
      correction = 140 * parseFloat(calcFontSize()) / 62.5;
      document.getElementById("hdrmargin").style.height = (( f_clientHeight() - correction ) *  .03 ) + "px";
      document.getElementById(elementId).style.height   = (( f_clientHeight() - correction ) *  .94 ) + "px";
      document.getElementById("ftrmargin").style.height = (( f_clientHeight() - correction ) *  .03 ) + "px";
    }
    else if ( htmlId === "bookXXX"  ) {
      elementId  = "bookText";
      correction = 140 * parseFloat(calcFontSize()) / 62.5;
      document.getElementById("hdrmargin").style.height = (( f_clientHeight() - correction ) *  .03      ) + "px";
      document.getElementById(elementId).style.height   = (( f_clientHeight() - correction ) *  .94      ) + "px";
      document.getElementById("bookImg").style.height   = (( f_clientHeight() - correction ) *  .94 - .6 ) + "px";
      document.getElementById("ftrmargin").style.height = (( f_clientHeight() - correction ) *  .03      ) + "px";
    }
    else  {
      elementId  = "";
      correction = 0;
    }
}
// ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼
function calcFontSize() {
  var height = screen.height;
  var width  = screen.width;
  var fontsz = 62.5; // default by 1024 × 768

  if      ( width === 320 &&  height === 396)
    ; // iPhone
  else if ( width / height >= 4 / 3)
    fontsz *= height / 768;
  else
    fontsz *= width / 1024;

  fontsz += "%"
  
  return fontsz;
}
// ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼
function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}
// ⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼⎼

