/*****************************************************************************

  -------------------------------
  |  Script:    fontChanger.js  |
  |-----------------------------|
  |  By:        Justin Johnson  |
  |-----------------------------|
  |  Created:   10/04/2007      |
  |-----------------------------|
  |  Modified:  05/19/2009      |
  -------------------------------

  <script type="text/javascript" src="/js/fontChanger.js"></script>
  ...
  <div id="fontChanger">
    <h1>Change Font Size</h1>
    <p>
      <a href="#" onClick="fontChanger(0, 'div_id', 12);">Font +</a>&nbsp;&nbsp;
      <a href="#" onClick="fontChanger(1, 'div_id', 12);">Font -</a>&nbsp;&nbsp;
      <a href="#" onClick="fontChanger(2, 'div_id', 12);">Reset Font</a>
    </p>
  </div>

  NOTE:  Use one of the following values as the argument
  0 = Increase font size
  1 = Decrease font size
  2 = Reset font size (12px by default)
  Anything else = nothing

*****************************************************************************/

function fontChanger(operation, div_name, default_size)
{
  // Setting up array of tags, use as many as you want.
  var tagList = new Array('p', 'td', 'li');

  // Looping through array of tags
  for(var i = 0; i < tagList.length; i++)
  {
    var content = document.getElementById(div_name);
    var allTags = content.getElementsByTagName(tagList[i]);
    for(var j = 0; j < allTags.length; j++)
    {
      // If a font size is set, use it, else use 12px by default
      if(allTags[j].style.fontSize)
      {
        var size = parseInt(allTags[j].style.fontSize.replace('px', ''));
      }
      else
      {
        var size = default_size;
      }

      // Based on what value operation is, do that operation
      // 0 = Increase font size by 1
      // 1 = Decrease font size by 1
      // 2 = Reset font size (12px by default)
      // Anything else, do nothing...
      switch(operation)
      {
        case 0:
          size += 1;
          break;

        case 1:
          size -= 1;
          break;

        case 2:
          size = default_size;
          break;

        default:
          break;
      }

      // Finally, re-write style with new font size
      allTags[j].style.fontSize = size + 'px';
    }
  }
}
