/////////////////////////////////////////////////////////////////////////////
//
// font size changer
//
/////////////////////////////////////////////////////////////////////////////


FontSizeChanger = {
  unit : "em",
  diff : 0.2,
  defaultSize : 0.8,
  minimumSize : 0.5,
  maximumSize : 1.3,
  cookieName : "fontsize",
  
  
  currentSize : "",
  getCookie : function (key,  tmp1, tmp2, xx1, xx2, xx3) {
    tmp1 = " " + document.cookie + ";";
    xx1 = xx2 = 0;
    len = tmp1.length;
    while (len > xx1) {
      xx2 = tmp1.indexOf(";", xx1);
      tmp2 = tmp1.substring(xx1 + 1, xx2);
      xx3 = tmp2.indexOf("=");
      if (tmp2.substring(0, xx3) == key) {
        return(unescape(tmp2.substring(xx3 + 1, xx2 - xx1 - 1)));
      }
      xx1 = xx2 + 1;
    }
    return("");
  },
  getCookie : function (key,  tmp1, tmp2, xx1, xx2, xx3) {
    tmp1 = " " + document.cookie + ";";
    xx1 = xx2 = 0;
    len = tmp1.length;
    while (len > xx1) {
      xx2 = tmp1.indexOf(";", xx1);
      tmp2 = tmp1.substring(xx1 + 1, xx2);
      xx3 = tmp2.indexOf("=");
      if (tmp2.substring(0, xx3) == key) {
        return(unescape(tmp2.substring(xx3 + 1, xx2 - xx1 - 1)));
      }
      xx1 = xx2 + 1;
    }
    return("");
  },
  setCookie : function (key, val, tmp) {
    tmp = key + "=" + escape(val) + "; ";
    tmp += "path=/; ";
//    tmp += "expires=Fri, 31-Dec-2030 23:59:59; "; // コメントアウトで短期クッキー
    document.cookie = tmp;
  },
  clearCookie : function (key) {
    document.cookie = key + "=" + "; expires=1-Jan-1997 00:00:00;";
  },
  change : function(cmd) {
    var nextSize = this.currentSize;
    if (cmd == "init") {
      var tmp = this.getCookie(this.cookieName);
      this.currentSize = (tmp == "") ? this.defaultSize : Number(tmp);
      nextSize = this.currentSize;
    }
    if (cmd == "L") {
      nextSize = Number(this.currentSize + this.diff);
      if (this.maximumSize != 0 && nextSize > this.maximumSize) {
        nextSize = this.maximumSize;
      }
    }
    if (cmd == "D") {
      nextSize = this.defaultSize;
    }
    if (cmd == "S") {
      nextSize = Number(this.currentSize - this.diff);
      if (nextSize < this.minimumSize) {
        nextSize = this.minimumSize;
      }
    }
    this.setCookie(this.cookieName, "" + nextSize);
    
    
    // NN
    if (document.layers) {
      window.alert("申し訳ございません。\nこのスクリプトはお使いのブラウザでは動作しません。");
      return false;
    }
    // MacIE4
    else if (( navigator.appVersion.indexOf("Mac",0) != -1) && (navigator.userAgent.indexOf("MSIE 4.0",0) != -1)) {
      window.alert("申し訳ございません。\nこのスクリプトはお使いのブラウザでは動作しません。");
      return false;
    }
    
    else if (document.body) {
      document.body.style.fontSize = ""+ nextSize + this.unit;
      this.currentSize = nextSize;
    }
    return false;
  },
  toDefault : function() {
    return this.change("D");
  },
  toLarge : function() {
    return this.change("L");
  },
  toSmall : function() {
    return this.change("S");
  },
  init : function() {
    return this.change("init");
  },
  isDefault : function() {
    if ("" + this.currentSize == "" + this.defaultSize) {
      return true;
    } else {
      return false;
    }
  }
};


