/*=========================================================


	Site Name   Chrysler Collection
	File Name   fontsize.js

	Create Date 2008/11/04
	Update Date 2008/11/04


==========================================================*/

/*----------------------------------------------------------

	Font Size Switcher Function

-----------------------------------------------------------*/

$(function(){
	var currentstyle = readCookie('fontStyle');

	if (currentstyle){
		//クッキーがある場合
		switchFont(currentstyle);
	}else{
		//クッキーがない場合(初回訪問時など)
		$("a.fsS").children("img").attr("src","/shared/images/fontsize_switcher/small_a.gif");
	};

	$("a.fsL").click(function(){
		switchFont("fontL");
		$(this).children("img").attr("src","/shared/images/fontsize_switcher/large_a.gif");
		$("a.fsM").children("img").attr("src","/shared/images/fontsize_switcher/medium.gif");
		$("a.fsS").children("img").attr("src","/shared/images/fontsize_switcher/small.gif");
		return false;
	});

	$("a.fsM").click(function(){
		switchFont("fontM");
		$(this).children("img").attr("src","/shared/images/fontsize_switcher/medium_a.gif");
		$("a.fsL").children("img").attr("src","/shared/images/fontsize_switcher/large.gif");
		$("a.fsS").children("img").attr("src","/shared/images/fontsize_switcher/small.gif");
		return false;
	});

	$("a.fsS").click(function(){
		switchFont("fontS");
		$(this).children("img").attr("src","/shared/images/fontsize_switcher/small_a.gif");
		$("a.fsL").children("img").attr("src","/shared/images/fontsize_switcher/large.gif");
		$("a.fsM").children("img").attr("src","/shared/images/fontsize_switcher/medium.gif");
		return false;
	});
});

function switchFont(className){

	$("body").removeAttr("class").addClass(className);

	if(className == "fontL"){
		$("a.fsL").children("img").attr("src","/shared/images/fontsize_switcher/large_a.gif");
	}else if(className == "fontM"){
		$("a.fsM").children("img").attr("src","/shared/images/fontsize_switcher/medium_a.gif");
	}else if(className == "fontS"){
		$("a.fsS").children("img").attr("src","/shared/images/fontsize_switcher/small_a.gif");
	}

	createCookie('fontStyle', className, 365);
};

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 var 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;
}
