// main javascript include file



/* ***********************************************************
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 {
    return document.body.clientHeight
  }
}



// mta stuff

// first define status strings

var DefaultStr="The web site of Mark Argent";
var HomeStr="Go to the first page of this web site";
var AboutStr="Biographical note";
var WorksStr="Details of my musical compositions and transcriptions";
var PerformancesStr="Diary of recent and forthcoming performances of my works";
var InProgStr="Current composition/transcription projects, and works which will soon be available here";
var ContactStr="Contact details";
var GardenStr="A month-by-month photographic diary of my garden";
var FurnitureStr="Photographs and details of some my furniture and wall hangings";
var SculptStr="Photographs of some of my sculpture";
var WriteStr="Details of some of my writings";
var TypoStr="Information on my typographic work";
var PerfStr="Information on my performing";







// function to hide email addresses from robots

// there's only one address, so no need for a lookup table


var str1="mail" 
var domna="marka";
var domnb="rgen";
var domnc="t.com";


var atstr="@";


function blat(){
  document.write("<A href=");
  document.write("'mailto:")
  document.write(str1 + atstr);
  document.write(domna);
  document.write(domnb);
  document.write(domnc);
  document.write("'>");
  if(arguments.length>0){
    document.write(arguments[0]);
    }
  else{
    document.write(str1 + atstr);
    document.write(domna);
    document.write(domnb);
    document.write(domnc);
  }
  document.write("</a>");
}




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



// function to provide a divider starting in maintext
// syntax: divider( <linewidth in pixels>  <proportion of padwidth> <colour>

function divider(){
  document.write("<p>");
  document.write("<img src='images/5x5.gif' height=3 width=300 style='background-color: ff9966;'>");
  document.write("<p>");
}






// this is a big function to handle images and text in sculpture and furniture
// pages. Arguments are:
//
// url: url of main image
// pos: ("left" or "right") to set main alignment
// content: (long) string containign all the actual text
// url2: (optional) second image
//

function addimageandtext(url,pos,content,url2){
  if(arguments.length<3)alert("3 or 4 arguments needed addimageandtext(url, pos, content,[ secondimg])");

  var inew=new Image();
  inew.src=url;

  var effectivewidth=getInsideWindowWidth()-50;  // reduced to allow for margns etc
  var availablewidth=effectivewidth-inew.width;
  var sufficientspace=1;
  var textwidth=availablewidth;
  var alignmentmode;

  if(textwidth>400){textwidth=400;}
  if(textwidth<250){
     textwidth=400; sufficientspace=0;
     if(effectivewidth<textwidth)textwidth=effectivewidth;
  }

  if(pos.indexOf("left")>-1){
    alignmentmode="left";alignmentmode="left";
    }
  else{
    if(pos.indexOf("right")>-1){
      alignmentmode="right";
      }
    else{
      alert("second argument to addimageadtext() must be 'left' or 'right'");
    }
  }

  var imgstr="<div style='float: " + alignmentmode + ";'><img src='" + url + "' name='" + url + "'></div>";

  var contentstr="<div class=" + alignmentmode + ">";

  contentstr=contentstr + "<div style='width: " + textwidth + "; padding: 15px; padding-top: 30px; text-align: justify;'>";
  contentstr=contentstr + content;
  contentstr=contentstr + "</div></div>";

  // it makes sense for valig to be middle if there is 1 image and top if there are two, so:
  var valignstr="middle";
  if(arguments.length==4)valignstr="top";


  document.write("<table width=100% cellpadding=0>");
  if(alignmentmode.indexOf("left")>-1){
    document.write("<tr valign=" + valignstr + "><td width=" + inew.width + ">");
    document.write(imgstr);
    document.write("</td>");
    if(sufficientspace==0){document.write("<tr>");}
    document.write("<td>");
    document.write(contentstr);

    if(arguments.length==4){document.write("<br><img src='" + url2 + "' align=right>");}
    }
  else{
    document.write("<tr valign=" + valignstr + "><td>");
    if(sufficientspace==0){
      document.write(imgstr);
      document.write("<tr><td>");
      document.write(contentstr);
      if(arguments.length==4){document.write("<br><img src='" + url2 + "' align=left>");}
      }
    else{
      document.write(contentstr);
      if(arguments.length==4){document.write("<br><img src='" + url2 + "' align=left>");}
      document.write("</td><td width=" + inew.width + ">");
      document.write(imgstr);
    }
  }
  document.write("</table><p>&nbsp;<p>");
}






// function to open window for general of an image
// first argument is the url of the image, the second argument (if present) is a caption

function newimgwin(url){
  var imgwin;
  var height;
  var width;
  var nimg=new Image();
  nimg.src=url;

  width=nimg.width;
  height=nimg.height;

  // phoenix returns 0 for these, so just in case:
  if(width<400)width=400;
  if(height<400)height=400;

  width=width+30;
  height=height+40;

  if (arguments.length==2) height=height+20; // allow for a caption

  var args="height=" + height + ",width=" + width + ",screenX=0,screenY=0,location=no,left=0,top=0,resizable=yes,status=no,toolbar=no,scrollbars=yes";
  imgwin=open(url,"imgwin",args);
  imgwin.document.write("<html>");
  imgwin.document.write("<head><link rel=stylesheet href='main.css' type='text/css'></head>");
  imgwin.document.write("<body>");
  imgwin.document.write("<center>");
  imgwin.document.write("<img src='" + url + "'>");
  imgwin.document.write("<p>");
  if(arguments.length==2){imgwin.document.write(arguments[1] + "<p>");}
  imgwin.document.write("<a href='javascript:self.close();'>click here to close</a>");
  imgwin.document.write("</body>");
  imgwin.document.write("</html>");
}




// function to open window for programme notes etc

var prognotewin=null;

function openprognote(url){
  var openwidth=getInsideWindowWidth()*0.5;
  var openheight=getInsideWindowHeight()*0.8;

  if(openwidth>600)openwidth=600;
  if(openheight>600)openheight=600;

  if(openwidth<300)openwidth=300;
  if(openheight<300)openheight=300;

  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(prognotewin!=null)prognotewin.close();
  prognotewin=open(url,"prognote",args);
}


