studying=Location.indexOf(".htm?study=on")>0;
var reference = false;
var maxCol = 1;
var currentCol = 0;

function title(str) {
  if (studying) document.body.style.margin=0;
  document.writeln('<h1>'+str);
}

function bible(passage, label) {
  if (!reference) {
    document.write('(');
    reference = true;
  }
  else {
    document.writeln(';');
  }
  document.write('<a href="../bible.htm?passage='+passage+'" target="detail">'+label+'</a>');
}

function endTitle() {
  if (reference) document.writeln(')');
  document.writeln('</h1>');
}

function beginPicture(tableWidth, cols) {
  if (studying) {
    if (cols != undefined) maxCol = cols;
    document.writeln('<blockquote><center>');
    document.writeln('<table width="'+tableWidth+'" border="1" bgcolor="#FFFFFF" cellpadding="0" cellspacing="0">');
  }
}

function picture(src, width, height, label) {
  if (studying) {
    currentCol++;

    if (maxCol>1) {
      if (currentCol==1) document.write('<tr>');
      document.write('<td><table border="0" height="100%" cellpadding="0" cellspacing="0"><tr><td>');
    }
    document.write('<tr><td><center>');
    document.writeln('<img src="'+src+'" width="'+width+'" height="'+height+'"></center></td></tr>');
    if (label != undefined && label != "") {
      document.writeln('<tr><td class="Highlight">');
      document.writeln(label);
      document.writeln('</td></tr>');
    }
    if (maxCol>1) {
      document.writeln('</td></tr></table>');
      if (currentCol==maxCol) {
        document.writeln('</td>');
        currentCol=0;
      }
    }
  }
}

function endPicture() {
  if (studying) document.writeln('</table></center></blockquote>');
}

function newstudy(url) {
  url=getpath(url);
  if (!studying) location.href=url;
  else location.href=url+"?study=on";
}

function readbible(passage) {
  openwindow(OrigDocRoot+Language+"/bible.htm?passage="+passage,option2);
}

function fixChildLinks(node) {
  for (var i=0; i<node.childNodes.length; i++) {
    var child=node.childNodes[i];
    if (child.nodeName=="A") {
      var href=child.href;
      if (href!=null && href.indexOf("?")==-1 && href.indexOf("javascript:")==-1) child.href+="?study=on";
    }
    else if (child.hasChildNodes()) {
      fixChildLinks(child);
    }
  }
}

function fixLinks() {
  if (studying) {
    var content=document.getElementById("content");
    if (content!=null) fixChildLinks(content);
    var pictures=document.getElementById("pictures");
    if (pictures!=null) pictures.style.display="block";
  }
}

