// Smooth Scroll --------------------------------------------------------------------------------------------------------

function smoothScroll() {
	var xScrollSpeed = 1;
	var yScrollSpeed = 1.1;
	
	var x1 = x2 = 0;
	var y1 = y2 = 0;
	if (document.documentElement) {
		x1 = document.documentElement.scrollLeft || 0;
		y1 = document.documentElement.scrollTop || 0;
	}
	if (document.body) {
		x2 = document.body.scrollLeft || 0;
		y2 = document.body.scrollTop || 0;
	}
	var x = Math.max(x1, x2);
	var y = Math.max(y1, y2);
	window.scrollTo(Math.floor(x/xScrollSpeed), Math.floor(y/yScrollSpeed));
	if (x>0 || y>0) {
		window.setTimeout("smoothScroll()", 10);
	}
}


// Popup -------------------------------------------------------------------------------

function openWin(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


// Fontsize -------------------------------------------------------------------------------

function setFontSize(num) {
	Element.setStyle('contents',{ "font-size" : fsAry[num] });
}

//default font-Array
var fsDefVal = 1;

//max font-Array
var maxVal = 6;

//minimal font-Array
var minVal = 0;

//cookie's limit
var fsDefLimit = 365;

//button img's fileType
var imgtype = ".gif";

//dim button's last string
var dimStr = "_dim";

var fsAry = new Array();
fsAry[0] = "85.7%";
fsAry[1] = "100%";
fsAry[2] = "116%";
fsAry[3] = "133%";
fsAry[4] = "150%";
fsAry[5] = "166%";
fsAry[6] = "183%";

var fsNum;
var path = "/";

function defCookie() {
	fsVal = fsDefVal;
	fsLimit = fsDefLimit;
	fsDate = new Date();
	fsDate.setTime(fsDate.getTime()+(fsLimit*24*60*60*1000));
	fsLib = "fsCookie=" + "@" + fsVal + "@fsValEnd" + ";";
	fsExpires = "expires=" + fsDate.toGMTString();
	fsPath = "path=" + path + "; ";
	document.cookie = fsLib + fsExpires + ";" + fsPath;
}

function burnCookie(burnNum) {
	fsLimit = fsDefLimit;
	fsDate = new Date();
	fsDate.setTime(fsDate.getTime()+(fsLimit*24*60*60*1000));
	fsLib = "fsCookie=" + "@" + burnNum + "@fsValEnd" + ";";
	fsExpires = "expires=" + fsDate.toGMTString();
	fsPath = "path=" + path + "; ";
	document.cookie = fsLib + fsExpires + ";" + fsPath;
}

function changeFontSize(type) {
	ckLib = document.cookie;
	ckCheck = ckLib.match(/fsCookie=@/);
	if(ckCheck == null) {
		defCookie();
		fsNum = fsDefVal;
	}else{
		var ckStart = ckLib.indexOf("fsCookie=@",0) + 10;
		var ckEnd = ckLib.indexOf("@fsValEnd",0);
		fsNum = ckLib.substring(ckStart,ckEnd);
	}
	
	if(type == "L") {
		fsNum = eval(fsNum);
		if(fsNum <= maxVal) {
			fsNum = fsNum + 1;
			burnCookie(fsNum);
			setFontSize(fsNum)
		}
	}else if(type == "S") {
		fsNum = eval(fsNum);
		if(fsNum >= minVal) {
			fsNum = fsNum - 1;
			burnCookie(fsNum);
			setFontSize(fsNum)
		}
	}else {
		setFontSize(fsNum);
	}
	
	largeStr = $("fsL").getAttribute("src");
	smallStr = $("fsS").getAttribute("src");
	if(fsNum == maxVal) {
		largeImg = largeStr.split(imgtype)[0] + dimStr + imgtype;
		$("fsL").setAttribute("src",largeImg);
		$("fsL").disabled = true;
		$("fsL").style.cursor = "default";
	}else{
		if(largeStr.indexOf(dimStr) != -1) {
			largeImg = largeStr.split(dimStr)[0] + imgtype;
			$("fsL").setAttribute("src",largeImg);
		}
		$("fsL").disabled = false;
		$("fsL").style.cursor = "pointer";
	}
	if(fsNum == minVal) {
		smallImg = smallStr.split(imgtype)[0] + dimStr + imgtype;
		$("fsS").setAttribute("src",smallImg);
		$("fsS").disabled = true;
		$("fsS").style.cursor = "default";
	}else{
		if(smallStr.indexOf(dimStr) != -1) {
			smallImg = smallStr.split(dimStr)[0] + imgtype;
			$("fsS").setAttribute("src",smallImg);
		}
		$("fsS").disabled = false;
		$("fsS").style.cursor = "pointer";
	}
}
Event.observe(window, 'load', changeFontSize);
