/* (C)Shinkousoku Printing Inc. http://www.sksp.co.jp/ */
/* require: jquery-1.4.2.min.js */

$(function(){
	
	var cookiePath = '/nekoyama2/';
	var cookieName = 'nekoyama_hospital_font_size';
	var createCookie = function(value, days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime() + (24 * 60 * 60 * 1000 * days));
			var expires = '; expires=' + date.toGMTString();
		}
		else {
			expires = '';
		}
		document.cookie = cookieName + '=' + value + expires + ';' + (cookiePath ? 'path=' + cookiePath : '');
	};
	var readCookie = function() {
		var cookies = document.cookie.split(';');
		for (var i = 0, cookieLength = cookies.length; i < cookieLength; i++) {
			if (cookies[i].indexOf(cookieName + '=') >-1) {
				var cookie = cookies[i].split('=');
				return cookie[1];
			}
		}
		return null;
	};

	var fontSize = {small:'13px', middle:'15px', large:'17px'};	
	var defaultSize = fontSize['small'];
	var cookieSize = readCookie();
	if (!fontSize[cookieSize]) cookieSize = 'small';
	
	var changeFontSize = function() {
		if ($(this).attr('class') == 'selected') return false;
		var selectedID = $(this).parent().attr('id');
		$('body').css('font-size', fontSize[selectedID]);
		$('#fontsize span').each(function(){
			$(this).removeClass('over').toggleClass('selected', ($(this).parent().attr('id') == selectedID));
		});
		createCookie(selectedID, 30);
	};
	var rollOverHandler = function(){
		if ($(this).attr('class') != 'selected') $(this).toggleClass('over');
	};
	$('#fontsize span').each(function(){
		$(this)
			.bind('mouseover', rollOverHandler)
			.bind('mouseout', rollOverHandler)
			.bind('click', changeFontSize);
		if ($(this).parent().attr('id') == cookieSize) $(this).trigger('click');
	});
	
});

function writeFontSizeController(indent) {
	var getIndent = function(indent) {
		var tabs = '\n';
		for (var i = 0; i < indent; i++) tabs += '\t';
		return tabs;
	};
	document.write(getIndent(indent) + '<dl>');
	document.write(getIndent(indent+1) + '<dt>文字サイズ</dt>');
	document.write(getIndent(indent+1) + '<dd id="small"><span>小</span></dd>');
	document.write(getIndent(indent+1) + '<dd id="middle"><span>中</span></dd>');
	document.write(getIndent(indent+1) + '<dd id="large"><span>大</span></dd>');
	document.write(getIndent(indent) + '</dl>');
}

