
// set default sizes
var growWrapDef = '1.5em';
var growRowDef = '1.4em';

var growWrap1 = '1.7em';
var growRow1 = '1.5em';

var growWrap2 = '1.9em';
var growRow2 = '1.8em';

function buildUI(){
  if (document.getElementById)
  {
  
    /* FONT SIZE INCREASE */
    //variable declaration
    var textGrowHTML           = '<div id="text_grow">Text Size: <a href="#" id="wd_js_reset" checked="checked">A</a><a href="#" id="wd_js_1">A</a><a href="#" id="wd_js_2">A</a></div>';
    var contentDefaultFontSize = document.getElementById('wrap_main_content').style.fontSize;
    var breadDefaultFontSize   = document.getElementById('h_row_3').style.fontSize;
    var currButton             = 1;
    
    //add UI Element to document tree
    document.body.innerHTML += textGrowHTML;
    var jsReset       = document.getElementById('wd_js_reset');
    var increaseByOne = document.getElementById('wd_js_1');
    var increaseByTwo = document.getElementById('wd_js_2');

    //init styles
    clearSetActive(0);
    
    //event handling
    jsReset.onmouseup = function(){
      adjustSize('wrap_main_content',growWrapDef);
      adjustSize('h_row_3',growRowDef);
      clearSetActive(0);
      setGrowCookie(0);
    };
    
    increaseByOne.onmouseup = function(){
     adjustSize('wrap_main_content',growWrap1);
     adjustSize('h_row_3',growRow1);
      clearSetActive(1);
      setGrowCookie(1);
    };
    
    increaseByTwo.onmouseup = function(){
      adjustSize('wrap_main_content',growWrap2);
      adjustSize('h_row_3',growRow2);
      clearSetActive(2);
      setGrowCookie(2);
    };
    
    cookieDetermine();
  }
  
};

//sets active button's state
function clearSetActive(butNum){
  var buttons = Array('wd_js_reset','wd_js_1','wd_js_2');
  for (var x=0; x<=2; x++){
    var currButton = eval("document.getElementById('"+buttons[x]+"');");
    if (x == butNum){
      currButton.style.className = 'growActive';
      currButton.style.color = '#33334C';
      currButton.style.textDecoration = 'underline';
      currButton.bactive = true;
    }else{
      currButton.className = '';
      currButton.style.color = '#a20000';
      currButton.style.textDecoration = '';
      currButton.bactive = false;
    }
  }
};

//adjusts specific elements fontSize
function adjustSize(id,val){
  var currObj = document.getElementById(id);
  currObj.style.fontSize = val;
};

//determine if cookie has been set and set up page size accordingly
function cookieDetermine(){
  var cookGrow = readCookie("sisfgrow");
  if (cookGrow!=null){
      var g = parseInt(cookGrow);
      clearSetActive(g); //set menu 'visually' according to cookie
      switch (g)
      {
        case 0:
          // do nothing (default)
          adjustSize('wrap_main_content',growWrapDef);
          adjustSize('h_row_3',growRowDef);
          break;
        case 1:
          adjustSize('wrap_main_content',growWrap1);
          adjustSize('h_row_3',growRow1);
          break;
        case 2:
          adjustSize('wrap_main_content',growWrap2);
          adjustSize('h_row_3',growRow2);
          break;
      } 
  }else{
      //set default
      document.cookie = 'sisfgrow=0;';
  }
};

//simply sets cookie for grow function
function setGrowCookie(val){
  document.cookie = 'sisfgrow='+val+';';
};

//parses cookie string for desired value
function readCookie(name){
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++){
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
};

//init on page load
function init() {
  if (arguments.callee.done) return;
  arguments.callee.done = true;
  if (_timer) clearInterval(_timer);
  //adjust font sizes
  buildUI();
  cookieDetermine();
};

/* for Mozilla/Opera9 */
if (document.addEventListener) {
  document.addEventListener("DOMContentLoaded", init, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
  document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
  var script = document.getElementById("__ie_onload");
  script.onreadystatechange = function() {
    if (this.readyState == "complete") {
      init(); // call the onload handler
    }
  };
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
  var _timer = setInterval(function() {
    if (/loaded|complete/.test(document.readyState)) {
      init(); // call the onload handler
    }
  }, 10);
}

/* for other browsers */
window.onload = init;