﻿/********************************************************************
  ポップアップ
*********************************************************************/

function newWindow (htmFile) {
  maniWindow = window.open(htmFile, "WindowName", "menubar=no,statusbar=yes,resizable=no,scrollbars=yes,height=500,width=640");
}


/********************************************************************
  ページスクロール
*********************************************************************/
function scroller(i){
		scroller_up(i,1000);
}
	
function scroller_up(i,y){
	y = y + (i - y)*.1;
	window.scroll(0,y);
	if (((i - y) <= .6)&&((i - y) >= -.6))
	{					
		y = i;
	}else{
		setTimeout("scroller_up("+i+","+y+")",1);
	}
}

function scroller_e(i){
	y = 1;
	kyoukai = i*.6;
	while(y <= kyoukai)
	{
		window.scroll(0,y);
		y = y + (y*.08);
    }
	while(y != i)
	{
		window.scroll(0,y);
		y = y + (i-y)*.08;
		if (((i - y) <= .6)&&((i - y) >= -.6))
		{					
			y = i;
		}		
	}
}

// ----------------------------------------------
// *** 03: SET FONT FAMILY AND FONT SIZE CSS ***
// ----------------------------------------------

document.write('<link rel="alternate stylesheet" type="text/css" href="./css/t/text_ws.css" title="text_s" />');
document.write('<link rel="alternate stylesheet" type="text/css" href="./css/t/text_wm.css" title="text_m" />');
document.write('<link rel="alternate stylesheet" type="text/css" href="./css/t/text_wl.css" title="text_l" />');
document.write('<link rel="stylesheet" type="text/css" href="./css/t/text_wm.css" title="text_m" />');


// ----------------------------------------------
// *** 04: STYLE SWITCHING ***
// ----------------------------------------------
function setActiveStyleSheet(title) {
	var i, a, main;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
			a.disabled = true;
			if(a.getAttribute("title") == title) a.disabled = false;
		}
	}
	createCookie("style", title, 365);
}

function getActiveStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
	}
	return null;
}

function getPreferredStyleSheet() {
	var i, a;
	for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		if(a.getAttribute("rel").indexOf("style") != -1
		&& a.getAttribute("rel").indexOf("alt") == -1
		&& a.getAttribute("title")
		) return a.getAttribute("title");
	}
	return null;
}

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

window.onload = function(e) {
	var cookie = readCookie("style");
	var title = cookie ? cookie : getPreferredStyleSheet();
	setActiveStyleSheet(title);
}

window.onunload = function(e) {
	var title = getActiveStyleSheet();
	createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
