var DOMAIN  = "http://www.nihondengi.co.jp/";
var IMG_DIR = DOMAIN + "_common/_img/";

function FontManager() {
  this.sizeObj = {
//    L : "16px",
//    M : "14px",
//    S : "12px"
	S : "12px",
    M : "14px",	
	L : "16px"
  };
  this.conId  = "fix";
  this.naviId = "size";
  this.fSize = this.getCookie("fsize");
};
FontManager.prototype.getCookie = function( id ) {
  //parse cookie
  c = document.cookie;
  ary = c.split(";");
  for (i=0; i<ary.length; i++) {
    if ( ary[i].indexOf( id ) != -1 ) return (ary[i].split("=")[1]);
  }
  return "M";
};
FontManager.prototype.changeSize = function( size ) {
  this.fSize = size;
  this.save();
  this.createMenu();
  document.getElementById(this.conId).style.fontSize = this.sizeObj[size];
};
FontManager.prototype.save = function() {
  var dt = new Date();
  dt.setHours(dt.getHours() + 24 * 30); //1month later
  dt = dt.toGMTString(); //GMT
  val = "fsize=" + this.fSize + ";expires=" + dt + ";path=/";
  document.cookie = val;
};
FontManager.prototype.createMenu = function() {
  var s = '<ul id="font">';
  for (var p in this.sizeObj) {
    var type = (p == this.fSize) ? "on" : "off";
    s += "<li id='large'><a href=\"javascript:fMng.changeSize('"+p+"')\">";
    s += "<img src='"+IMG_DIR+"font_"+ p + type +".gif' /></a></li>";
  }
  s += "</ul>";
  document.getElementById(this.naviId).innerHTML = s;
};
FontManager.prototype.includeCSS = function() {
  path = DOMAIN + "_css/font_" + this.fSize + ".css";
  document.write('<link rel="stylesheet" href="'+path+'" type="text/css">');
};

var fMng = new FontManager();
