$(function(){
	$('#check_top a').click(function () {
		$("#check_top").animate({opacity: "hide"}, 500);
		$("#q1").animate({opacity: "show"}, 500);
		return false;
	});
	
	$(".next").click(function () {
							   
		var prId = $(this).parent().attr('id');
	
		var checkVal =  $("input[name="+ prId +"]:checked").val();
		
		if( checkVal == null){
			
			alert("チェックしてから進んでください");

		} else {
			
			$(this).parent().hide();
			$(this).parent().next().show();
			
		};

	});
	$(".prev").click(function () {
		$(this).parent().hide();
		$(this).parent().prev().show();
	});
	
});

function zannen(){
	
	$("#result").text("");
	
	var qCount = 15;
	var ansArr = new Array(qCount);
	var a;
	var point = 0;
	var dispText;
	var textArr = new Array();
	
	/* 得点算出 */
	
	for(i=1;i<=qCount;i++){
		
		a = $("input[name=q" + i + "]:checked").val();
		ansArr[i] = a;
		
		if( a == null){
			
			alert("すべてチェックしてください");
			break;
			
		} else {

			switch(i){
				
				case 4:
				case 7:
				case 10:
				case 11:
				case 12:
				case 14:
				
					if( a == "no" ) {
						
						point++;
						
					}
				
					break;
					
				default:
				
					if( a == "yes") {
						
						point++;
						
					}
				
					break;
				
			};
			
		};
		
	};
	
	/* 表示テキスト分岐 */
	if( a != null) {
	
		if( point < 1 ){
			dispText = "残念度はなんとゼロ！でもちょっと心配です。完璧過ぎて近寄りがたいと思われていませんか？この機会に巷にいる残念な人たちのことを理解してみては。";
		} else if( point < 6 ){
			
			/* */
			textArr[1] = "セーフです。残念な人だとは思われていないでしょう。新しい人脈を得ることでより、残念から遠ざかることができるかもしれません。";
			textArr[2] = "安心してください。残念な人だとは思われていません。でも、周囲に残念な人が多いと感じてしまうのは、あなたにその傾向があるからかもしれませんよ。";
			textArr[3] = "大丈夫です。残念な人だとは思われていません。感覚的なところがあって、論理に弱いところがあるかもしれませんが、それもご愛敬でしょう。";
			textArr[4] = "今のところ、残念な人だとは思われていないようですので、ご安心を。";
	
			if( ansArr[5] == "yes" && ansArr[8] == "no" && ansArr[12] == "yes"){ /* 5 のみ */
				dispText = textArr[1];
			} else if ( ansArr[5] == "no" && ansArr[8] == "yes" && ansArr[12] == "yes" ) { /* 8 のみ */
				dispText = textArr[2];
			} else if ( ansArr[5] == "no" && ansArr[8] == "no" && ansArr[12] == "no" ) { /* 12 のみ */
				dispText = textArr[3];
			} else if ( ansArr[5] == "yes" && ansArr[8] == "yes" && ansArr[12] == "yes" ) { /* 5と8 */
				dispText = textArr[Math.floor(Math.random()*2+1)];
			} else if ( ansArr[5] == "yes" && ansArr[8] == "no" && ansArr[12] == "no" ) { /* 5と12 */
				i = textArr[Math.floor(Math.random()*2+1)];
				if(i==2){
					i++;
				}
				dispText = textArr[i];
			} else if ( ansArr[5] == "no" && ansArr[8] == "yes" && ansArr[12] == "no" ) { /* 8と12 */
					i = textArr[Math.floor(Math.random()*2+1)];
				if(i<=1){
					i = i+2;
				}
				dispText = textArr[i];
			} else if( ansArr[5] == "yes" && ansArr[8] == "yes" && ansArr[12] == "no" ) { /* ぜんぷ */
				dispText = textArr[Math.floor(Math.random()*3+1)];
			} else {
				dispText = textArr[4];
			};
			
		} else if( point < 11 ){
			textArr[1] = "残念な人だと思われている可能性アリ。とくに人間関係がかたまってしまっているのが気になります。新しい友人から刺激を受ける機会を増やすと、脱残念できるかも？";
			textArr[2] = "残念な人だと思われているかもしれません。周囲に残念な人しかいないのは、あなたが紛れもなく残念な人だからかもしれませんよ。";
			textArr[3] = "あなたを残念だと言っている人はいるかもしれません。論理性に欠けると、陰で言われている可能性があります。後輩や部下に馬鹿にされる前に、思考法のトレーニングを積んでみては。";
			textArr[4] = "すでに残念な人だと影で囁かれている可能性が少なくありません。この機会に脱・残念しましょう。";
	
			if( ansArr[5] == "yes" && ansArr[8] == "no" && ansArr[12] == "yes"){ /* 5 のみ */
				dispText = textArr[1];
			} else if ( ansArr[5] == "no" && ansArr[8] == "yes" && ansArr[12] == "yes" ) { /* 8 のみ */
				dispText = textArr[2];
			} else if ( ansArr[5] == "no" && ansArr[8] == "no" && ansArr[12] == "no" ) { /* 12 のみ */
				dispText = textArr[3];
			} else if ( ansArr[5] == "yes" && ansArr[8] == "yes" && ansArr[12] == "yes" ) { /* 5と8 */
				dispText = textArr[Math.floor(Math.random()*2+1)];
			} else if ( ansArr[5] == "yes" && ansArr[8] == "no" && ansArr[12] == "no" ) { /* 5と12 */
				i = Math.floor(Math.random()*2+1);
				if( i >= 2){
					i = 3;
				}
				dispText = textArr[i];
			} else if ( ansArr[5] == "no" && ansArr[8] == "yes" && ansArr[12] == "no" ) { /* 8と12 */
				i = Math.floor(Math.random()*2+1);
				if(i <= 1){
					i = i+2;
				}
				dispText = textArr[i];
			} else if( ansArr[5] == "yes" && ansArr[8] == "yes" && ansArr[12] == "no" ) { /* ぜんぷ */
				dispText = textArr[Math.floor(Math.random()*3+1)];
			} else {
				dispText = textArr[4];
			};
	
		} else if( point < 15 ){
			textArr[1] = "かなりの残念度です。とくに人間関係・・年々友達が減ってきていませんか？　見放されてしまう前に、コミュニケーション能力を見なおしてみては。";
			textArr[2] = "周囲から残念だと思われているでしょう。環境や他人のせいにしないでまずは自分の悪い所を見なおしてみては。";
			textArr[3] = "お気の毒ですが、残念な人だと思われている可能性が高いです。論理性がないと陰で言われているかも。プライオリティ思考を身につけて。";
			textArr[4] = "残念な人だと言われている可能性が大。このままでは、職場の人や家族からつめたい視線を感じてしまうかも。一刻も早く脱・残念しましょう。";
			
			if( ansArr[5] == "yes" && ansArr[8] == "no" && ansArr[12] == "yes"){ /* 5 のみ */
				dispText = textArr[1];
			} else if ( ansArr[5] == "no" && ansArr[8] == "yes" && ansArr[12] == "yes" ) { /* 8 のみ */
				dispText = textArr[2];
			} else if ( ansArr[5] == "no" && ansArr[8] == "no" && ansArr[12] == "no" ) { /* 12 のみ */
				dispText = textArr[3];
			} else if ( ansArr[5] == "yes" && ansArr[8] == "yes" && ansArr[12] == "yes" ) { /* 5と8 */
				dispText = textArr[Math.floor(Math.random()*2+1)];
			} else if ( ansArr[5] == "yes" && ansArr[8] == "no" && ansArr[12] == "no" ) { /* 5と12 */
				i = Math.floor(Math.random()*2+1);
				if(i==2){
					i++;
				}
				dispText = textArr[i];
			} else if ( ansArr[5] == "no" && ansArr[8] == "yes" && ansArr[12] == "no" ) { /* 8と12 */
				i = Math.floor(Math.random()*2+1);
				if(i==1){
					i = i+2;
				}
				dispText = textArr[i];
			} else if( ansArr[5] == "yes" && ansArr[8] == "yes" && ansArr[12] == "no" ) { /* ぜんぷ */
				dispText = textArr[Math.floor(Math.random()*3+1)];
			} else {
				dispText = textArr[4];
			};
	
		} else {
			dispText = "最強の残念度です。あなたは逆に大物かもしれません。このまま残念街道を突っ走っていただきたい！　・・あ、周囲の迷惑は顧みてね。";
		};
	
		point = point/16*100;
		var encText = encodeURI("残念な人診断結果：残念な人度" + point + "％　残念な人診断はこちら！ ") + "http://bit.ly/amJFWQ %23zannennahito";
		
		$("#result").append("<div id='result_main'><h3>あなたの残念な人度は</h3><p class='point'>" + point + "<span>％</span></p><p class='text_area'>" + dispText + "</p></div><form name='copy_form' id='copy_form'><p>診断結果をコピー:</p><textarea id='copy_area' name='copy_text' cols='40' rows='3' onfocus='setTimeout(function(){document.copy_form.copy_text.select()},0);'>残念な人度"+ point + "%　" + dispText + "</textarea><!--[if IE]><br /><input type='button' class='copy' onClick='textcopy()' value='診断結果をコピー' /><![endif]--></form><a href='http://twitter.com/home?status="+ encText +"' class='tweet' target='_blank'><img src='images/tweet_btn.gif' alt='結果をtweetする' width='234' height='34' /></a>");
		$("#result").animate({opacity: "show"}, 500);
		
		
	};
};


