/*
 * fontresizer.js 0.1
 * Copyright (c) 2008 C.M.A. Co.,Ltd.
 *
 * Last Added: 2008-01-09
 *
 */

// フォントサイズ変更ボタンを表示

$(function(){
	$("#fontresize").html("<ul id='fontSize'><li class='size001'><img src='http://www.seri.or.jp/shared/img/tl_fontsize_001.gif' alt='文字サイズ変更' width='105' height='22' /></li><li class='size002'><a href='javascript:void(0);' onclick=\"fontresize('70%','fontS');\" class='fontS'><img src='http://www.seri.or.jp/shared/img/btn_fontsize_s.gif' alt='小' width='19' height='22' class='btn' /></a></li><li class='size003'><a href='javascript:void(0);'  onclick=\"fontresize('80%','fontM');\" class='fontM'><img src='http://www.seri.or.jp/shared/img/btn_fontsize_m.gif' alt='中' width='19' height='22' class='btn' /></a></li><li class='size004'><a href='javascript:void(0);'  onclick=\"fontresize('100%','fontL');\" class='fontL'><img src='http://www.seri.or.jp/shared/img/btn_fontsize_l.gif' alt='大' width='27' height='22' class='btn' /></a></li></ul>");
	});

//フォントサイズ変更 via http://blog.4galaxy.net/

$(function(){
	$("body").css("font-size",$.cookie('fsize'));
	// Cookieが空のときの初期値ボタンを反転
	if($.cookie('fclass') == null){
		$("#fontSize a.fontM").find('img').each(function(){
			this.currentSrc = this.getAttribute('src').replace(/(\.gif|\.jpg|\.png)/, "_on$1");
			$(this).attr('src',this.currentSrc);
		});
	}
	$("#fontSize a").each(function(){
	 // ボタンを表示
		if($(this).attr('class') == $.cookie('fclass')){
			$(this).find('img').each(function(){
				this.currentSrc = this.getAttribute('src').replace(/(\.gif|\.jpg|\.png)/, "_on$1");
				$(this).attr('src',this.currentSrc);
			});
		}
	});
});
function fontresize(size,c){
 	// Cookie生成
	if(c != $.cookie('fclass')){
			$("body").css("font-size",size);
			$.cookie("fsize",size,{expires:30,path:'/'});
			$.cookie("fclass",c,{expires:30,path:'/'});
		// Cookie内のclass値とボタンのclass値が同等なら反転
		$("#fontSize a").each(function(){
			if($(this).attr('class') == $.cookie('fclass')){
				$(this).find('img').each(function(){
					this.currentSrc = this.getAttribute('src').replace(/(\.gif|\.jpg|\.png)/, "_on$1");
					$(this).attr('src',this.currentSrc);
				});
			// 不等ならデフォルト状態に戻す
			}else if($(this).attr('class') != $.cookie('fclass')){
				$(this).find('img').each(function(){
					this.currentSrc = this.getAttribute('src').replace(/_on(\.gif|\.jpg|\.png)/, "$1");
					$(this).attr('src',this.currentSrc);
				});
			}
		});
	}
}
