$(document).ready(function(){
	chk.init();
});


var chk = {
	init : function(){
		this.erase("div#result_area");
	},

	erase : function(element){
		$(element).animate({opacity: 0}, 0);
		$(element).fadeOut(0);
	},

	calc : function(){
		formObj = document.getElementById('form1');
		var point = 0;
		for(var i=0;i<formObj.length;i++){
			if(formObj[i].type=="radio" && formObj[i].checked) point += parseInt(formObj[i].value);
		}
		this.res(point);
	},

	res : function(point){
		if(point > 30){
			this.load('div#answerArea','./answer/5.html','1.0')
		} else if(point > 24) {
			this.load('div#answerArea','./answer/4.html','1.0')
		} else if(point > 18) {
			this.load('div#answerArea','./answer/3.html','1.0')
		} else if(point > 12) {
			this.load('div#answerArea','./answer/2.html','1.0')
		} else {
			this.load('div#answerArea','/etc/answer/1.html','1.0')
		}
	},

	load : function(element,url,op){
		$(element).animate({opacity: 0}, 100);
		$(element).fadeIn(0);
		$(element).load(url,null,function(){
			$(element).animate({opacity: op}, 300);
		});
		this.jump('answerArea');
	},

	gy: function (d) {
		gy = d.offsetTop
		if (d.offsetParent) while (d = d.offsetParent) gy += d.offsetTop
		return gy
	},

	//現在位置の取得
	offsetY: function(){
		if(document.all){
			if(document.compatMode == "CSS1Compat"){
				y = document.documentElement.scrollTop;
			}else{
				y = document.body.scrollTop;
			}
		}else if(window.pageXOffset !== undefined){
			y = window.pageYOffset;
		}else{
			y = window.scrollY;
		}
		return y;
	},

	//スクロールの実行
	scroll: function(targetY){
		var nowY = this.offsetY();
		this.scrollSet(nowY,targetY);
	},

	//idへのスクロール
	jump: function(IdName){
		var Anchor = document.getElementById(IdName);
		var posY = this.gy(Anchor);
		this.scroll(posY);
	},

	scrollSet : function(nowY,targetY){
		var diffY,stepY,moveY;
		diffY = .1 * (targetY - nowY);
		if(diffY > 0){
			stepY = Math.ceil(diffY);
		}else{
			stepY = Math.floor(diffY);
		}
		moveY = nowY + stepY;
		if(stepY > 0 && moveY <= targetY || stepY < 0 && moveY >= targetY ){
			window.scroll(0,moveY);
			nowY += stepY;
			setTimeout("chk.scrollSet(" +nowY+ "," +targetY+ " )",1);
		}else{
			return true;
		}
	}
}
