var fontchanger = function(){

	var imageDirPath = 'img/';				//imageディレクトリーへのパス
	var addIncludeBaseDirFlag = true;		//include.jsのbaseDirをパスに追加
	var COOKIE_NAME = 'temp_ft';		//クッキー名
	var COOKIE_LIMIT = 7;					//一週間クッキー保持
	var defaultID = 'size-m';	//初期文字サイズセットID

	if( addIncludeBaseDirFlag && typeof include != 'undefined' && typeof include.baseDir != 'undefined' ){
		//include.jsがインクルードされbaseDirが宣言されている場合
		imageDirPath = include.baseDir + imageDirPath;
	}

	/**
	 * デフォルトの文字サイズセット
	 */
	var sizeList = [
		//           通常時の画像 ,          選択時の画像 ,         サイズ ,         ID名
		{'contents' : 'fonts.gif', 'click':'fonts_ov.gif', 'size' : '90%' , 'id' : 'size-s'},
		{'contents' : 'fontm.gif', 'click':'fontm_ov.gif', 'size' : '100%', 'id' : 'size-m'},
		{'contents' : 'fontb.gif', 'click':'fontb_ov.gif', 'size' : '120%', 'id' : 'size-l'}
	];

	/**
	 * イベントを追加する関数
	 * @param	target	string		イベントを追加する対象
	 * @param	type	string		追加するイベント名
	 * @param	func	function	追加する関数
	 */
	var addEventListener = function(target, type, func){
		if( target.attachEvent ){
			target.attachEvent("on" + type, func);
		}else if( target.addEventListener ){
			target.addEventListener(type, func, true);
		}else{
			target["on" + type] = func;
		}
	};

	/**
	 * Cookie読み書き
	 */
	var cookie = {};
	cookie.write = function(key, data, limit){
		if( !navigator.cookieEnabled ){
			return;			//クッキー利用不可
		}
		day = new Date();
		day.setTime(day.getTime() + (limit * 1000 * 60 * 60 * 24));
		document.cookie = key + "=" + escape(data) + ";expires=" + day.toGMTString();
	};
	cookie.read = function(key){
		if( !navigator.cookieEnabled || typeof(key) == "undefined"){
			return null;	//クッキー利用不可
		}
		key += "=";
		string = document.cookie + ";";			// クッキー情報を読み込む
		start = string.indexOf(key);				// キーワードを検索
		if (start != -1){							// キーワードと一致するものあり
			end = string.indexOf(";", start);		// 情報の末尾位置を検索
			return unescape(string.substring(start + key.length, end));  // データ取り出し
		}
		return null;
	}

	var pub = {};

	pub.target = null;


	/**
	 * 文字サイズ変更
	 */
	pub.size = function(id, target_id){
		cookie.write(COOKIE_NAME, id, COOKIE_LIMIT);
		var target = target_id ? document.getElementById(target_id) : document.body;

		for(var i = 0;i < sizeList.length;i++){
			if( sizeList[i]['id'] == id ){
				target.style.fontSize = sizeList[i]['size'];
				var img = document.getElementById(sizeList[i]['id']);
				img.src = imageDirPath + sizeList[i]['click'];
			}else{
				var img = document.getElementById(sizeList[i]['id']);
				img.src = imageDirPath + sizeList[i]['contents'];
			}
		}
	};

	/**
	 * 文字変更のリンクロード
	 */
	pub.write = function(id){
		var init_id = cookie.read(COOKIE_NAME);
		if( !init_id ){
			init_id = defaultID;
		}
		//初期設定
		addEventListener(window, 'load', function(){
			pub.size(init_id, id);
		});

		//クリック用文字列＋リンク作成
		var text = '<ul>';
		for( var i = 0; i < sizeList.length ; i++  ){
			if( init_id == sizeList[i]['id'] ){
				text += '<li><img src="' + imageDirPath + sizeList[i]['click'] + '" id=\''+sizeList[i]['id']+'\' style="cursor: pointer;" onclick="fontchanger.size(\''+sizeList[i]['id']+'\',\''+(id?id:'')+'\');" /></li>';
			}else{
				text += '<li><img src="' + imageDirPath + sizeList[i]['content'] + '" id=\''+sizeList[i]['id']+'\' style="cursor: pointer;" onclick="fontchanger.size(\''+sizeList[i]['id']+'\',\''+(id?id:'')+'\');" /></li>';
			}
		}
		text += '</ul>';
		document.write(text);
	};

	return pub;
}();

//ID指定なしでbody指定;
fontchanger.write('container');