sizeFont = {
  defaultSize: 11,  
  sizeUnit: "px",   
  bodyOnly: false,  
  incAmount: 1,     
  maxSize: 16,      
  minSize: 10,      
  
 
  increaseBtn: "Increase",
  decreaseBtn: "Decrease",
  resetBtn:    "Reset",   
  
  skipList:  [],  
  rulesList: [],   
  controlList: [], 
  
  standards: [document.getElementById, document.styleSheets, document.createElement, typeof document.body != "undefined" && typeof document.body.setAttribute != "undefined"],

  setControls: function (sel,mn,mx) {
    this.controlList[this.controlList.length] = arguments;
  },

  init: function () {
    var rules = [], sizediv, size, i, j;
    for ( i=0; i<this.standards.length; i++ ) { if ( !this.standards[i] ) return; }

    for ( i=0; i<document.styleSheets.length; i++ ) {
      if (document.styleSheets[i].rules) {
        rules.push( document.styleSheets[i].rules );
      } else if (document.styleSheets[i].cssRules) { 
        rules.push( document.styleSheets[i].cssRules );
        for (j=0; j<rules[i].length; j++) {
          if ( rules[i][j].type == 3 ) 
            rules.push( rules[i][j].styleSheet.cssRules );
        }
      }
  
      if (document.styleSheets[i].imports) {  
        for (j=0; j<document.styleSheets[i].imports.length; j++) 
          rules.push( document.styleSheets[i].imports[j].rules );
      }
    } 
    
    sizediv = document.getElementById("sizer");
    if (!sizediv) { alert("Don't forget the sizer div!"); return; }
    if ( this.increaseBtn ) {
      var frm = sizediv.appendChild( document.createElement("FORM") );
      var incbtn = frm.appendChild( document.createElement("BUTTON") );
      var decbtn = frm.appendChild( document.createElement("BUTTON") );
      var resetbtn = frm.appendChild( document.createElement("BUTTON") );      
      incbtn.appendChild( document.createTextNode(sizeFont.increaseBtn) );
      decbtn.appendChild( document.createTextNode(sizeFont.decreaseBtn) );
      resetbtn.appendChild( document.createTextNode(sizeFont.resetBtn) );      
      incbtn.setAttribute( "id", "inc");  decbtn.setAttribute( "id", "dec");
      incbtn.setAttribute( "accessKey", "i");  decbtn.setAttribute( "accessKey", "r");
      incbtn.onclick = this.adjust;  decbtn.onclick = this.adjust; resetbtn.onclick = this.reset;
    } 
    sizediv.style.display = "block";
    
    for ( i=0; i<rules.length; i++ ) { this.holdSizeRules( rules[i] ); }
    
    size = (window.location.search)? window.location.search.slice(1): getCookie("fontSize")? getCookie("fontSize"): null;
    if ( size && !isNaN( parseFloat(size) ) && this.bodyRule ) 
      this.adjust( parseFloat(size) - parseFloat(this.bodyRule.style.fontSize) );

  },
  

  holdSizeRules: function (rules) {
    var i, j;
    rulesCheck:
    for ( i=0; i<rules.length; i++) {
      if ( rules[i].style && rules[i].style.fontSize ) { 
        if ( !rules[i].selectorText ) { document.getElementById("sizer").style.display = "none"; return; }
        
        if ( rules[i].selectorText.match( new RegExp("\\bbody\\b", "i") ) ) {
          this.bodyRule = rules[i]; 
          if ( this.bodyOnly ) { this.rulesList.push(rules[i]); return; }
        }
        
        for ( j=0; j<this.skipList.length; j++) {
          if ( rules[i].selectorText.match( new RegExp("\\b" + this.skipList[j] + "\\b", "i") ) ) 
            continue rulesCheck;
        }
        this.rulesList.push(rules[i]);

        for ( j=0; j<this.controlList.length; j++) {
          if ( rules[i].selectorText.match( new RegExp("\\b" + this.controlList[j][0] + "\\b", "i") ) ) 
            this.controlList[j][3] = parseFloat(rules[i].style.fontSize) / parseFloat(this.bodyRule.style.fontSize);
        }
      }
    }  
  
  },
  
  adjust: function (n) {
    var bodySize = parseFloat(sizeFont.bodyRule.style.fontSize);
    var rules = sizeFont.rulesList;  
    if ( typeof n != "number" ) 
      n = sizeFont.incAmount * ( (this.id == "inc")? 1: -1 );

    if ( sizeFont.maxSize ) {
      if ( n > 0 && bodySize + n > sizeFont.maxSize )
        n = sizeFont.maxSize - bodySize;
    }
    if ( sizeFont.minSize ) {
      if ( n < 0 && bodySize + n < sizeFont.minSize )
        n = sizeFont.minSize - bodySize;
    }
    if ( n == 0 ) return false;
    
    for (var i=0; i<rules.length; i++) {
      if ( parseFloat(rules[i].style.fontSize) + n > 0 ) { 
        if ( !sizeFont.handleControlList( rules[i] ) )
          rules[i].style.fontSize = parseFloat( rules[i].style.fontSize) + n + sizeFont.sizeUnit;
      }
    }
    setCookie( "fontSize", sizeFont.bodyRule.style.fontSize, 180, "/" );
    return false; 
  },


  handleControlList: function (rule) {   
    var sz, cl = this.controlList; 
    for (var i=0; i<cl.length; i++) {  
      if ( rule.selectorText.match( new RegExp("\\b" + cl[i][0] + "\\b", "i") ) ) {
        sz = Math.round( parseFloat(this.bodyRule.style.fontSize) * cl[i][3] );
        sz = Math.max(cl[i][1], sz); sz = Math.min(cl[i][2], sz);
        rule.style.fontSize = sz + this.sizeUnit;
        return true;
      } 
    }
    return false;
  },
  
  reset: function() {
    sizeFont.adjust( sizeFont.defaultSize - parseFloat( sizeFont.bodyRule.style.fontSize ) );
    deleteCookie("fontSize", "/");
    return false;
  }
  
}  

if (!Array.prototype.push) {
	Array.prototype.push =  function() {
		for (var i=0; arguments[i]; i++) this[this.length] = arguments[i];
		return this.length;
	}
}  

