/*
 *	common.js
 *
 *	# jQuery1.2.6以上が必要です。
 */

/************************************************************************************************
	※クッキー対応ヴァージョン
*/
$(document).ready(function(){
	/*------------------------------------
	 * 引数一覧
	 * 1,イベントハンドラ（小）
	 * 2,フォントサイズ（小サイズ）
	 * 3,イベントハンドラ（中）
	 * 2,フォントサイズ（中サイズ）
	 * 5,イベントハンドラ（大）
	 * 2,フォントサイズ（大サイズ）
	 * 7,アニメーションスピード
	 */
	forFontSize('small','69%','middle','75%','large','88%','500');
});


function forFontSize(s,sf,m,mf,l,lf,speed){
	
	/*------------------------------------
	 * イベントハンドラ
	 */
	var small = $('#'+ s);
	var middle = $('#'+ m);
	var large = $('#'+ l);
	var body = $('body');
	var speed2 = 0;
	
	if(readCookie('fontSize')){
		fontSize = readCookie('fontSize');
	}else{
		setCookie('fontSize','middle',365);
		$('dd#small').html('<img src="/img/ico-fontS.gif" width="16" height="16" alt="小" />');
		$('dd#middle').html('<img src="/img/ico-fontM-ovr.gif" width="20" height="20" alt="中" />');
		$('dd#large').html('<img src="/img/ico-fontL.gif" width="24" height="24" alt="大" />');
	}
	

	/*------------------------------------
	 * 各種ボタン動作
	 */
	small.click(function(){
		$('dd#small').html('<img src="/img/ico-fontS-ovr.gif" width="16" height="16" alt="小" />');
		$('dd#middle').html('<img src="/img/ico-fontM.gif" width="20" height="20" alt="中" />');
		$('dd#large').html('<img src="/img/ico-fontL.gif" width="24" height="24" alt="大" />');
		body.animate({
			fontSize: sf
		}, speed );
		setCookie('fontSize','small',365);
	});
	middle.click(function(){
		$('dd#small').html('<img src="/img/ico-fontS.gif" width="16" height="16" alt="小" />');
		$('dd#middle').html('<img src="/img/ico-fontM-ovr.gif" width="20" height="20" alt="中" />');
		$('dd#large').html('<img src="/img/ico-fontL.gif" width="24" height="24" alt="大" />');
		body.animate({
			fontSize: mf
		}, speed );
		setCookie('fontSize','middle',365);
	});
	large.click(function(){
		$('dd#small').html('<img src="/img/ico-fontS.gif" width="16" height="16" alt="小" />');
		$('dd#middle').html('<img src="/img/ico-fontM.gif" width="20" height="20" alt="中" />');
		$('dd#large').html('<img src="/img/ico-fontL-ovr.gif" width="24" height="24" alt="大" />');
		body.animate({
			fontSize: lf
		}, speed );
		setCookie('fontSize','large',365);
	});
	
	/*------------------------------------
	 * クッキーロード
	 */
	if(readCookie('fontSize')){
		if(readCookie('fontSize')=='small'){
		$('dd#small').html('<img src="/img/ico-fontS-ovr.gif" width="16" height="16" alt="小" />');
		$('dd#middle').html('<img src="/img/ico-fontM.gif" width="20" height="20" alt="中" />');
		$('dd#large').html('<img src="/img/ico-fontL.gif" width="24" height="24" alt="大" />');
			body.animate({
				fontSize: sf
			}, speed2 );
		}
		if(readCookie('fontSize')=='middle'){
		$('dd#small').html('<img src="/img/ico-fontS.gif" width="16" height="16" alt="小" />');
		$('dd#middle').html('<img src="/img/ico-fontM-ovr.gif" width="20" height="20" alt="中" />');
		$('dd#large').html('<img src="/img/ico-fontL.gif" width="24" height="24" alt="大" />');
			body.animate({
				fontSize: mf
			}, speed2 );
		}
		if(readCookie('fontSize')=='large'){
		$('dd#small').html('<img src="/img/ico-fontS.gif" width="16" height="16" alt="小" />');
		$('dd#middle').html('<img src="/img/ico-fontM.gif" width="20" height="20" alt="中" />');
		$('dd#large').html('<img src="/img/ico-fontL-ovr.gif" width="24" height="24" alt="大" />');
			body.animate({
				fontSize: lf
			}, speed2 );
		}
	}
}

/********************************************************************************************************
	Cookie操作
**/
function setCookie(name,value,days){
	// デフォルトでは有効期限がないので一時的クッキーになる。
	var expires = '';
	
	// クッキーの有効期限を日数で指定。
	if(days){
		var date = new Date();
		date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
		expires = '; expires = ' + date.toGMTString();
	}
	
	// クッキーに名前、値、有効期限を設定。
	document.cookie = name + '=' + value + expires + '; path=/';
}

function readCookie(name){
	// 指定されたクッキーを探し、値を返す。
	var searchName = name + '=';
	var cookies = document.cookie.split(';');
	for(i=0,L=cookies.length; i<L; i++){
		var c = cookies[i];
		while(c.charAt(0) == ' '){
			c = c.substring(1, c.length);
		}
		if(c.indexOf(searchName) == 0){
			return c.substring(searchName.length, c.length);
		}
	}
	return null;
}

function eraseCookie(name){
	// 指定されたクッキーを消去
	setCookie(name, '', -1);
}

// popup-width,hight
function m_win(url,windowname,width,height) {
 var features="location=no, menubar=no, status=yes, scrollbars=yes, resizable=yes, toolbar=no";
 if (width) {
  if (window.screen.width > width)
   features+=", left="+(window.screen.width-width)/2;
  else width=window.screen.width;
  features+=", width="+width;
 }
 if (height) {
  if (window.screen.height > height)
   features+=", top="+(window.screen.height-height)/2;
  else height=window.screen.height;
  features+=", height="+height;
 }
 window.open(url,windowname,features);
}

// close window
function WinC(){
    window.opener = window;
    var win = window.open(location.href,"_self");
    win.close();
}
