//文字(サイズ+色) 用Script jQuery利用
/*==============================
クッキーの有効期限（7日）
==============================*/
function save(n, v) {
	var key = new Date();
	key.setTime(key.getTime() + 24 * 60 * 60 * 7 * 1000);
	var exp = key.toGMTString();
	document.cookie = n + '=' + v + ';expires=' + exp + ';path=/';
	return null;
}

/*===============クッキーの読み出し===============*/
function read(n) {
	n = n + '=';
	var s = null;
	var x = document.cookie.length;
	var l = n.length;
	for (i = 0; i < x; i++) {
		if (document.cookie.substring(i, i + l) == n) {
			if (document.cookie.indexOf (";", i + l) == -1) {
				s = document.cookie.substring(i + l, document.cookie.length);
			} else {
				s = document.cookie.substring(i + l, document.cookie.indexOf (";", i + l));
			}
		}
	}
	return s;
}

/*===============フォントサイズ変更の設定===============*/
function view(r) {
	var f_size = document.body.style.fontSize;//現在値
	var num = 10;//増減幅
	var s = (f_size.substr(0,f_size.length-1)-0) ;//数値化(％除去)
	if(r == '-'){
		s = s - num;
		if (s < 70) { s = 70; }           //フォントの限界縮小値70%指定
	}else{
		s = s + num;
		if (s > 300) { s = 300; }           //フォントの限界縮大値300%指定
	}
	document.body.style.fontSize = s + '%';
	save('fontsize', s);
	return null;
}

/*===============色セットcss変更===============*/
/*色指定css linkタグ書換*/
function active_css(r){
  if(r < 1 || r > 2 ){ /*範囲外設定値ガード*/
	  r = 1;
  }
  c_css =  document.getElementById("color"+r);
  
  if(c_css){
	css = c_css.getAttribute("href");
  }
  
  s_css =  document.getElementById("color_css");
  if(c_css != null && css.length>0){
	document.getElementById("color1").setAttribute("rel","alternate stylesheet");
  	document.getElementById("color2").setAttribute("rel","alternate stylesheet");
	s_css.setAttribute("href",css);
	s_css.setAttribute("rel","stylesheet");
  }
  return null;
}
/*===============色設定変更===============*/
function colors(r) {
	active_css(r);	//アクティブ切替
	save('colorset', r);	//保存	
	return null;
}

/*========初回ページ読み込み時の設定(初期化)========*/
function init(f) {
	var set1, set2;
	
	set1 = read('fontsize') ;
	if (f == true || set1 == null) {
		set1 = 100; //初期値 100%
		save('fontsize', set1);               
	}
	document.body.style.fontSize = set1 + '%';//フォントサイズを%で指定

	set2 = read('colorset') ;
	if (f == true || set2== null) {
		set2 = 1; //初期値 カラータイプ1
		save('colorset', set2);                 //色セット
	}
	active_css(set2);	//cssセット

	return null;
}

/*===============リセットの設定===============*/
function re_set() {
	init(true); //初期化
	return null;
}
function plus(){
	view('+');
}
function minus(){
	view('-');
}	
function white(){
	colors(1);
}
function black(){
	colors(2);
}
//ツールボタン書き出し
/*
function f_tools(){
	var tool_code = " <ul id='t_jtools'>" +
            "<li id='t_fsize'>文字サイズの変更<ul>" +
                "<li id='t_plus'><a href='#' onclick='plus()'>大</a></li>" +
                "<li id='t_minus'><a href='#' onclick='minus()'>小</a></li>" +
            "</ul></li>" +
            "<li id='t_color'>背景を変更<ul>" +
                "<li id='t_black'><a href='#' onclick='black()'>黒</a></li>" +
                "<li id='t_white'><a href='#' onclick='white()'>白</a></li>" +
            "</ul></li>" +
            "<li id='t_reset'><a href='#' onclick='re_set()'>リセット</a></li>" +
          "</ul>" ;
	//$("#toolbar").prepend(tool_code);
	document.getElementById("toolbar").innerHTML= tool_code;
}*/
//検索窓------------
function serchIni(){
	label = document.getElementById("srchlabel");
	if(label){
		label.setAttribute("class","inlined");
	}
	word = document.getElementById("srchword");
	if(word){
		word.onfocus=sercWOn;
		word.onblur=sercWOff;
	}

}
function sercWOn(){
	if(label){
		label.setAttribute("class","hide");
	}
}
function sercWOff(){
	word = document.getElementById("srchword");
	if(word){
		if(word.value==""){
			label = document.getElementById("srchlabel");
			if(label){
				label.setAttribute("class","inlined");
			}
		}
	}
}

function MainToolsIni(){
	//f_tools();
	serchIni();
	init(false); 
}
function BlogToolsIni(){
	init(false); 
}

