// フォントサイズ変更


function setFontSize() {
	var fs = readCookie("size_change");
	switch(fs) {
		case "font_small":
			// do nothing
			break;
		case "font_medium":
			// do nothing
			break;
		case "font_large":
			// do nothing
			break;
		default:
			fs = "font_small";
	}
	createCookie("size_change", fs, 365);
	setActiveFontStyleSheet(fs);
	setActiveIcon();
}

function changeFontSize(fs) {
	createCookie("size_change", fs, 365);
	setActiveFontStyleSheet(fs);
	setActiveIcon();
}

function setActiveFontStyleSheet(title) {
  if(document.getElementById && document.createTextNode) {
		var i, a, b, main;
	  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
	    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
		  if(a.getAttribute("title").indexOf("font_") != -1) {
			  a.disabled = true;
		  }
	      if(a.getAttribute("title") == title) {
			  a.disabled = false;
		  }
		  
	    }
	  }
	}
}

function setActiveIcon() {
	var a, b, c;
	var fs = readCookie("size_change");
	var pathToFolder;
	switch(fs) {
		case "font_small":
			// do nothing
			break;
		case "font_medium":
			// do nothing
			break;
		case "font_large":
			// do nothing
			break;
		default:
			fs = "font_small";
	}
	a = document.getElementById("img_font_small");
	pathToFolder = getFolderFromPath(a.getAttribute("src"));
	a.setAttribute("src", pathToFolder + "font_small.gif");	
	b = document.getElementById("img_font_medium");
	b.setAttribute("src", pathToFolder + "font_medium.gif");	
	c = document.getElementById("img_font_large");
	c.setAttribute("src", pathToFolder + "font_large.gif");	
	
	switch(fs) {
		case "font_small":
			a.setAttribute("src", pathToFolder + fs + "_on.gif");	
			break;
		case "font_medium":
			b.setAttribute("src", pathToFolder + fs + "_on.gif");	
			break;
		case "font_large":
			c.setAttribute("src", pathToFolder + fs + "_on.gif");	
			break;
		default:
			a.setAttribute("src", pathToFolder + fs + "_on.gif");	
	}

}

function getFolderFromPath(path) {
	var fileInfo = new Array();
	var folderPath = "";
	fileInfo = path.split('/');
	for (i = 0; i < fileInfo.length - 1; i++) {
		folderPath += fileInfo[i] + '/';
	}
	return folderPath;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

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;
}

