//<![CDATA[

var cookie;
var defaultFontSize;
var ratio;

function addEvent (elm, listener, func) {
	try {
		elm.addEventListener(listener, func, false);
	}
	catch(e) {
		elm.attachEvent("on" + listener, func);
	}
}


/* set cookie ----------------------------------------------------------------*/
function setCookie(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=/';
}

/* read cookie ---------------------------------------------------------------*/
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;
}

/* change fontSize ------------------------------------------------------------*/

function changeFontSize(ratio) {
	if (ratio == 100) {
		defaultFontSize = 84;
	}
	else {
		if (72 < parseInt(defaultFontSize) && parseInt(ratio) < 0 ) {
			defaultFontSize = parseInt(defaultFontSize) + parseInt(ratio);
		}
		if (0 < parseInt(ratio) && parseInt(defaultFontSize) < 124) {
			defaultFontSize = parseInt(defaultFontSize) + parseInt(ratio);
		}
	}
	
	document.body.style.fontSize = defaultFontSize + '%';
}

/* change font size when onload-----------------------------------------------*/
function changeFontSizeWhenOnload() {
	cookie = readCookie('fontSize');
	defaultFontSize = cookie ? cookie : 84;
	changeFontSize(0);
}

/* set font size cookie when onload ------------------------------------------*/
function setCookieWhenUnload() {
	setCookie('fontSize', defaultFontSize, 365);
}

/* event ----------------------------------------------------------------------*/

addEvent(window, 'load'   , changeFontSizeWhenOnload);
addEvent(window, 'unload' , setCookieWhenUnload);


//]]>
