  // Change these values to suit your environment
  var steps = 0; // default step level
  var max_steps = 3; // highest level
  var min_steps = 0; // lowest level
  var step_percent = 0.01; // the percent font change; the size will always change a minimum of 1 px
  var skip_class = "no-resize"; // the designated class name to not resize

  // Call this to increase the font size
  function increase_font_size()
  {
    if(steps < max_steps)
    {
      increase_size(document.body)
      steps++;
    }
  }

  // Call this to decrease the font size
  function decrease_font_size()
  {
    if(steps > min_steps)
    {
      decrease_size(document.body)
      steps--;
    }
  }

  // Recursively increase font sizes
  function increase_size(element)
  {
    var old_size, new_size, old_height, new_height;
    for(var i = 0; i < element.childNodes.length; i++)
    {
      if(element.childNodes[i].childNodes.length > 0)
      {
        if(element.childNodes[i].className.indexOf(skip_class) == -1)
        {
          increase_size(element.childNodes[i]);
        }
      }
      if(element.childNodes[i].style != null)
      {
        if(element.childNodes[i].className.indexOf(skip_class) == -1)
        {
          old_size = parseInt(get_style(element.childNodes[i], "font-size").replace("px", ""));
          new_size = Math.ceil(old_size + (old_size * step_percent));
          if(!isNaN(new_size))
          {
            element.childNodes[i].style.fontSize = new_size + "px";
          }
          old_height = parseInt(get_style(element.childNodes[i], "line-height").replace("px", ""));
          new_height = Math.ceil(old_height + (old_height * step_percent));
          if(!isNaN(new_height))
          {
            element.childNodes[i].style.lineHeight = new_height + "px";
          }
        }
      }
    }
  }

  // Recursively decrease font sizes
  function decrease_size(element)
  {
    var old_size, new_size, old_height, new_height;
    for(var i = 0; i < element.childNodes.length; i++)
    {
      if(element.childNodes[i].childNodes.length > 0)
      {
        if(element.childNodes[i].className.indexOf(skip_class) == -1)
        {
          decrease_size(element.childNodes[i]);
        }
      }
      if(element.childNodes[i].style != null)
      {
        if(element.childNodes[i].className.indexOf(skip_class) == -1)
        {
          old_size = parseInt(get_style(element.childNodes[i], "font-size").replace("px", ""));
          new_size = Math.floor(old_size - (old_size * step_percent));
          if(!isNaN(new_size))
          {
            element.childNodes[i].style.fontSize = new_size + "px";
          }
          old_height = parseInt(get_style(element.childNodes[i], "line-height").replace("px", ""));
          new_height = Math.floor(old_height - (old_height * step_percent));
          if(!isNaN(new_height))
          {
            element.childNodes[i].style.lineHeight = new_height + "px";
          }
        }
      }
    }
  }

  // Get the current font size of an element
  function get_style(element, style)
  {
    var camelize = function(str)
    {
      return str.replace(/\-(\w)/g, function(str, letter)
      {
        return letter.toUpperCase();
      });
    };

    if(element.currentStyle)
    {
      return element.currentStyle[camelize(style)];
    }
    else if(document.defaultView && document.defaultView.getComputedStyle)
    {
      return document.defaultView.getComputedStyle(element, null).getPropertyValue(style);
    }
    else
    {
      return element.style[camelize(style)]; 
    }
    return fs;
  }

  function setCookie(name, value, days)
  {
    var expiration_date = new Date();
    expiration_date.setDate(expiration_date.getDate() + days);

    document.cookie = name + "=" + escape(value);
    document.cookie += (days == null) ? "" : "; expires = " + expiration_date.toGMTString();
  }

  function getCookie(name)
  {
    var value = '';

    if(document.cookie.length > 0)
    {
      var c_start = document.cookie.indexOf(name + "=");

      if(c_start != -1)
      {
        c_start = c_start + name.length + 1;
        var c_end = document.cookie.indexOf(";", c_start);

        if(c_end == -1)
        {
          c_end = document.cookie.length;
        }

        value = unescape(document.cookie.substring(c_start, c_end));
      }
    }

    return value;
  }

  window.onload = function(e)
  {
    var cookie = getCookie("TextResize");
    var title = cookie ? cookie : -1;

    for(var i = 0; i < cookie; i++)
    {
      increase_font_size();
    }
  }

  window.onunload = function(e)
  {
    setCookie("TextResize", steps, 365);
  }

