// hardacker.com genealogy tree
// copyright 2001-2002 Andy Hardacker  andy@hardacker.com
var isNN4 = document.layers?1:0;
var isIE4 = document.all?1:0;
var isIE5 = (document.getElementById && document.all)?1:0; 
var isNN6 = (document.getElementById && !document.all)?1:0;
var iDown = "../gen/images/down.gif";
var iRight = "../gen/images/right.gif";
// generic functions
function getObject(oID) {
 if (document.getElementById) return document.getElementById(oID);
 if (document.all) return eval("document.all." + oID);
 return null;
}
function setPosition(objectID, relY ) { 
  var wOff = (isNN4 || isNN6) ? window.pageYOffset : document.body.scrollTop;
  wOff = wOff + relY; 
  var oBlock = getObject(objectID); 
//  oBox.style.visibility = "visible";       
  if (isNN4) oBlock.top = wOff;
  else oBlock.style.top = wOff+"px";
}
// list functions
function toggle(listID) {  
  var oList = getObject(listID);
  var oImg  = getObject("i" + listID);
  if (oList.style.display == "none") {
    oList.style.display = "block";
    if (oImg != null) oImg.src = iDown;
  } else {
    oList.style.display = "none";
	if (oImg != null) oImg.src = iRight;
  }	
}
function toggleAll(action) {                          
  var i;
  var oContainer = null;
  var oImg = null;
  if (document.getElementsByTagName) {
    oContainer = document.getElementsByTagName("li");
  }
  if (oContainer != null) { 
    for (i=0;i<oContainer.length;i++) {
   // alert("id = " + oWhatever[i].getAttribute("id"));
      if (oContainer[i].className=="container") {
       oContainer[i].style.display = (action=="collapse") ? "none" : "block";
       oImg = getObject("i"+oContainer[i].id);
       if (oImg != null)
         oImg.src = (oContainer[i].style.display == "none") ? iRight : iDown; 
      }
    }
  }
}
function toggleStyle() {
  if (fancyStyle.disabled) {
    fancyStyle.disabled = false;
    plainStyle.disabled = true;
    getObject("styleToggle").innerHTML = "Plain";
    getObject("button-expand").style.visibility= "visible";
    getObject("button-collapse").style.visibility= "visible";    
    addIFrame();
//    document.getElementByid("styleMessage").display = "block";  
  } else { 
    toggleAll("expand");  
    plainStyle.disabled = false;
    fancyStyle.disabled = true;
    getObject("styleToggle").innerHTML = "Fancy";    
    getObject("button-expand").style.visibility= "hidden";
    getObject("button-collapse").style.visibility= "hidden";    
    removeIFrame();  
  } 
} 
// IFrame functions
function addIFrame() {
  if (getObject("iperson") != null) return;
  // Netscape does this right
  if (isNN6) {
    var oIF = document.createElement("iframe");
    oIF.setAttribute("id","iperson");
    oIF.setAttribute("name","iperson");
    oIF.setAttribute("src","");
    oIF.setAttribute("frameBorder","0");
    document.getElementById("drag").appendChild(oIF);
  } else {
    var oIF = getObject("iframe-container");
    if (oIF != null)
      oIF.innerHTML = "<iframe id='iperson' name='iperson' frameborder='0'></iframe>";
  }
  sizeIFrame(); 
  setPosition("drag", dragYTop);  
}  
function removeIFrame() {
  if (getObject("iperson") == null) return;
  var oIF = getObject("iframe-container");
  if (oIF != null && oIF.removeChild)
    oIF.removeChild(document.getElementById("iperson"));
}
function loadIFrame(sURL) {
  // or not, as the case may be
  var oIF = getObject("iperson");
  if (oIF == null) return true;
  oIF.src = sURL;
  return false;
}
function sizeIFrame() {
  var oIF = getObject("iperson");
  if (oIF == null) return;
  if (oIF.style.display == "none") return;
  var winH = 0, winW = 0, h = 0;
  if (document.documentElement && document.documentElement.clientHeight) { 
    // IE6
    winH = document.documentElement.clientHeight;  
    winW = document.documentElement.clientWidth; 
    h = document.body.scrollTop; // ?         
  } else if (isIE4 || isIE5) {
    winH = document.body.clientHeight;
    winW = document.body.clientWidth;
    h = document.body.scrollTop;
  } else {
    // Netscape
    winH = window.innerHeight - 25;
    winW = window.innerWidth;
    h = window.pageYOffset;
  }  
  //alert("winh, winW, scrollTop = " + winH +","+winW+","+ h); 
  oIF.style.height = (winH - (h + 70)) + "px";
  oIF.style.width  = (winW/2 + 50) + "px";  
}
var dragYTop = -100 ; //-130;
// used in onload of files placed in iframe
function showIFrame() {
  if (isNN4) return;
  toggleIFrame("show");
  setPosition("drag", dragYTop);
}  
function toggleIFrame(action) {
//alert("action = " + action);
  if (action == null || typeof action == "undefined") action = "";
  var oPerson = getObject("iperson");
  var sButton = getObject("iperson-toggle");
  if ((action == "" || action == "show") && oPerson.style.display == "none") {
    oPerson.style.display = "block";
    sButton.innerHTML = "Hide";
  } else if ((action == "" || action == "hide") && oPerson.style.display != "none") {
    oPerson.style.display = "none";
    sButton.innerHTML = "Show";
  }
}
// diary functions
function openDiary(url) {
  var diary = window.open(url, "diary", "toolbar=no,menubar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,width=450,height=450");
  //if (!diary.opener) diary.opener = self;
  //if (self != top) diary.opener = self.parent;  
  return false;
}
// page initialization
var fancyStyle = null;
var plainStyle = null;
function initTree() {
  if (isNN4) return;
  // in NN6 the atttribute doesn't work but setting the property does. Aargh.
  //if (isNN6) {    
  var styles = document.getElementsByTagName("style");
  for (var i=0;i<styles.length;i++) {
    if (styles[i].getAttribute("title") == "plainTree") {
      styles[i].disabled = true;
      plainStyle = styles[i];
    } else if (styles[i].getAttribute("title") == "fancyTree") {  
       fancyStyle = styles[i];   
    }
  }  
  var oDrag = getObject("drag");
  // check for style or whatever?
  //oDrag.style.display = "block";

  addIFrame();
  document.getElementById("iperson").setAttribute("src","../gen/intro.html");  
  window.onResize = sizeIFrame;
}  	

