/*
 * pageFonts.js
 *
 * IT-Sundhed
 * Lasse F. Pedersen
 * 24/Nov/2003
 *
 * Toggles font size (large / small)
 */

// Standard font size
var stdFontSize = null

/*
 * Font size of the 'page' container
 */

function toggleFontSize() {

  var amount;

  // Change anchor container and anchor so it acts like a toggling switch
  var con = document.getElementById("fontSizeItem");
  var elm = document.getElementById("fontSizeAnchor");
  
  if(con.className == "smallertext") {

    amount = -3;
    con.className = "largertext"
    elm.innerHTML = "St&#248;rre tekst";

  } else {

    amount = 3;
    con.className = "smallertext"
    elm.innerHTML = "Mindre tekst";

  }

  // Get 'page' container and current font size
  var pageelm = document.getElementById("text");
  var pagesiz = 0;
  
  if(pageelm.currentStyle != null) {
    pagesiz = parseInt(pageelm.currentStyle.fontSize);
  } else {
    pagesiz = parseInt(document.defaultView.getComputedStyle(pageelm, null).fontSize);
  }

  // Set original font size if not set
  if(!stdFontSize) {
    stdFontSize = pagesiz;
  }

  toggleFontSizeDeep(pageelm, amount);
  
  // Defined in pageLoad.js
  recalcHeight();

}

// Recurse
function toggleFontSizeDeep(pageelm, amount) {
  
  // Got children? Recurse
  if(pageelm.hasChildNodes) {
  
    var children = pageelm.childNodes

    for(var i = 0; i < children.length; i++) {
      toggleFontSizeDeep(children[i], amount);
    }
  
  }

  var elmcss = pageelm.style;
  var curcss = null;

  if(pageelm != "[object Text]" && pageelm != "[object Comment]") {
    if(pageelm.currentStyle != null) {
      curcss = pageelm.currentStyle;
    } else if(document.defaultView != null) {
      curcss = document.defaultView.getComputedStyle(pageelm, null);
    }
  }

  if(!elmcss || !curcss)
    return;
    
  if(pageelm.tagName == "FONT") {
    
    if(amount > 0)
      pageelm.size = parseInt(pageelm.size) + 1;
    else
      pageelm.size = parseInt(pageelm.size) - 1;
      
  } else if(curcss.fontSize.indexOf("px") != -1) {
    
    elmcss.fontSize = parseInt(curcss.fontSize) + amount + "px";

  }

}

