var page_title;
var page_title_prefix = "";
var other_title_callbacks = [];
/* set_page_title_prefix(t)
 *
 * Sets the prefix for the page title.
 */
function set_page_title_prefix(t) {
  page_title_prefix = t;
}
/* override_page_title(t)
 *
 * Overrides set_title() below (before it's called), allowing for titles which
 * exist in no elements at all.
 */
function override_page_title(t) {
  page_title = t;
}
/* set_title()
 *
 * Sets the title tag to the content of the first <H1>... or the element with
 * id "effective-title".
 *
 * If you've stuck any function(title) {} callbacks into other_title_callbacks,
 * those will also be called.
 */
function set_title() {
  if(!page_title) {
    var heads = document.getElementsByTagName("h1");
    if(heads.length > 0) {
      var title_text_node;
      for(var i=0; i<heads.item(0).childNodes.length; i++) {
        if(heads.item(0).childNodes.item(i).data) {
          title_text_node = heads.item(0).childNodes.item(i);
          break;
        }
      }
    } else if(document.getElementById("effective-title")) {
      title_text_node=document.getElementById("effective-title").firstChild;
    } else {
    }
    if(title_text_node) {
      page_title = title_text_node.data;
    } else {
      page_title = "";
    }
  }
  var new_title = page_title_prefix + ": ";
  // The first head should be the one we want
  new_title = new_title + page_title;
  for(var i=0; i<other_title_callbacks.length; i++)
    other_title_callbacks[i](page_title);
  document.title = new_title;
  return true;
}


