// CSS情報
var css = new Array(2);
css[0] = "http://www.sweetpea.co.jp/common/css/fontsize_m.css";    // フォントサイズ 標準
css[1] = "http://www.sweetpea.co.jp/common/css/fontsize_l.css";  // フォントサイズ大 拡大

// クッキー作成
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;
}

// フォントサイズセット
function setFontSize( size ){

	createCookie( "fontsize", size, 365 );
	reflectionCss( size );
	if (size == "normal"){
		document.FontSizeM.src=IMGsrc[0][1];
		document.FontSizeL.src=IMGsrc[1][0];
	}
	else if (size == "large"){
		document.FontSizeM.src=IMGsrc[0][0];
		document.FontSizeL.src=IMGsrc[1][1];
	}
	else{
		document.FontSizeM.src=IMGsrc[0][0];
		document.FontSizeL.src=IMGsrc[1][0];
	}
}

// フォントサイズゲット
function getFontSize(){
	var size = "large";	// デフォルトのサイズは「拡大」
	var cookie = readCookie( "fontsize" );
	return cookie ? cookie : size;
}

// フォントサイズ画像チェンジ
var fontsize = getFontSize();
var icon0 = "";
var icon1 = "";
if (fontsize == "normal"){
	icon0 = "http://www.sweetpea.co.jp/common/images/font_n_on.gif";
	icon1 = "http://www.sweetpea.co.jp/common/images/font_l.gif";
}else if (fontsize == "large"){
	icon0 = "http://www.sweetpea.co.jp/common/images/font_n.gif";
	icon1 = "http://www.sweetpea.co.jp/common/images/font_l_on.gif";
}else{
	icon0 = "http://www.sweetpea.co.jp/common/images/font_n_on.gif";
	icon1 = "http://www.sweetpea.co.jp/common/images/font_l.gif";
}

IMGsrc = new Array();
IMGsrc[0] = new Array("http://www.sweetpea.co.jp/common/images/font_n.gif","http://www.sweetpea.co.jp/common/images/font_n_on.gif");
IMGsrc[1] = new Array("http://www.sweetpea.co.jp/common/images/font_l.gif","http://www.sweetpea.co.jp/common/images/font_l_on.gif");


//文字サイズ変更ボタンHTML
var fontsize_html = ''
+'<div id="headerfont">\n'
+'<img src="http://www.sweetpea.co.jp/common/images/headerfont.gif" alt="文字サイズ" />\n'
+'<a href="javascript:setFontSize(\'normal\');" onfocus="if(document.all)this.blur()"><img src="' +icon0+ '" alt="標準" name="FontSizeM" /></a>\n'
+'<a href="javascript:setFontSize(\'large\');"  onfocus="if(document.all)this.blur()"><img src="' +icon1+ '" alt="拡大" name="FontSizeL" /></a>\n'
+'</div>\n';





// フォントサイズ反映
function reflectionCss( size ){
	if( size == null ){
		size = getFontSize();
	}
	var i, obj;
	for( i = 0; ( obj = document.getElementsByTagName("link")[i] ); i++ ){
		if( obj.getAttribute("rel").indexOf("style") != -1 && obj.getAttribute("title") ){
			if( obj.getAttribute("title") == size ){
				obj.disabled = false;
			}
			else{
				obj.disabled = true;
			}
		}
	}
}

var di = document.implementation;

function loadCss( obj ){
	var i, n;
	var cssfile = ""
	var size = getFontSize();

	// 読込順を正しくしないと動きがおかしくなる可能性がある。
	// → テストしてみたが、HTMLEventsのバージョンに関わらず、
	//    同じ読み込み順で大丈夫そう。

	// HTMLEvents2.0 => <ex> FireFox1.5
	if( di && di.hasFeature( 'HTMLEvents', '2.0' ) ){
		switch( size ){
			case 'normal': n = new Array( 0, 1 ); break;
			default: n = new Array( 1, 0 ); break;
		}

	// HTMLEvents2.0でない => <ex> IE6.0
	}else{
		switch( size ){
			case 'normal': n = new Array( 0, 1 ); break;
			default: n = new Array( 1, 0 ); break;
		}
	}
	
	// ２つのcssファイルをロード
	for( i = 0; i < n.length; i++ ){
		switch( n[i] ){
			case 0: document.writeln('<link rel="stylesheet" title="normal" type="text/css" href="' + css[0] +'">'); break;
			default: document.writeln('<link rel="stylesheet" title="large" type="text/css" href="' + css[1] +'">'); break;
		}
	}

	document.close();
}

function addEvent( obj, eventType, func ){
	if( di && di.hasFeature( 'HTMLEvents', '2.0' ) ){
		window.addEventListener( 'load', initCss, false );
	}else{
		initCss();
	}
}

// ロード時
function initCss(){
		reflectionCss( null );
}


// CSS読込
loadCss( window );

// イベント追加
addEvent( window, 'load', initCss );


