//これは債務専門司法書士事務所のスクリプトです
//jquery-1.2.6.min.jsをフレームワークに使っています

$(init);


////////////////////////////////////////////////////////////////////
//初期化処理
////////////////////////////////////////////////////////////////////
function init()
{
	//
	//javascriptがON時にbodyにクラスを加えてスタイルをコントロール
	//
	$("body").addClass("onscript");
	
	
	//
	//借金問題Ｑ＆Ａ
	//
	var saimu_faq = $("#main dl.saimu-faq dt");
	saimu_faq.hover(
		function(){ $(this).css("cursor","pointer"); },
		function(){ $(this).css("cursor","default"); }
	);
	
	saimu_faq.toggle(
		function(){ $(this).next().slideDown("fast");},
		function(){ $(this).next().slideUp("fast"); }
	);

	//
	//あなたの依頼する事務所は大丈夫ですか？
	//
	$("#topics02-q div.submit a").click(
		function(){
			var checkedradio = $("#topics02-q input[type='radio']:checked");
			var response;
			if(checkedradio.length==4){
				var total
					= Number(checkedradio.get(0).value)
					+ Number(checkedradio.get(1).value)
					+ Number(checkedradio.get(2).value)
					+ Number(checkedradio.get(3).value);
				if		(total==20){response = "迷わず依頼しましょう";}
				else if(total>=18){response = "依頼しても大丈夫でしょう";}
				else if(total>=16){response = "よく考えて依頼しましょう";}
				else if(total>=12){response = "他も探してみては";}
				else			   {response = "お勧めしません";}
			}else{
				response = "全ての質問にお答えください";
			}
			$("#topics02-response div").fadeOut("fast",function(){
				$(this).text(response).fadeIn("slow");
			});
			return false;
		}
	);
	
	
	
	//
	//借金問題YES NO
	//
	$("#yesorno p.select a").one( "click", procYesOrNo );
	
	
	//
	//もう一度やるの処理
	//
	$("#yesorno div.yn-result button").click( procReset );	

	//
	//過払金返還シミュレーターのフォーム
	//
	$("#calcu dl input")
		.focus(function(){ $(this).css("backgroundColor","#FFFFFF"); } )
		.blur (function(){ $(this).css("backgroundColor","#E6F0E7"); } )
	$("#calcu div.submit input").hover(
		function(){ $(this).css("backgroundPosition","0px -35px").css("cursor","pointer"); },
		function(){ $(this).css("backgroundPosition","0px 0px"); }
	);
	$("#calcu table tbody tr:odd *").css("backgroundColor","#F4F9F4");
}


////////////////////////////////////////////////////////////////////
//YesとNo画像をクリックした場合の処理
////////////////////////////////////////////////////////////////////
function procYesOrNo()
{
	//
	//対象エレメントを取得
	//
	var ynshowid = $(this).attr("href");
	ynshowid = ynshowid.split("#");
	ynshowid = "#" + ynshowid[1];
	var ynshowyn = "yn-" + $(this).attr("class");
	
	
	//
	//次の質問及び結果の表示
	//
	$(this).attr("href","javascript:void(0)").append("<span></span>");
	$(this).hover(
		function(){$(this).css("cursor","default");},
		function(){$(this).css("cursor","default");}
	)
	$(this).next().fadeOut("fast");
	$(this).prev().fadeOut("fast");
	$(ynshowid).addClass(ynshowyn).fadeIn("slow");
	
	//
	//スクロール制御
	//現状のスクロールバーの位置を取得して、次に表示される内容の高さを加えたところまでスクロール
	//させる。
	//その際にマージンを25pxとる。
	//
	var margin    = 25;
	var myscrolly = document.documentElement.scrollTop || document.body.scrollTop;
	var height    = $(ynshowid).height();
	
	//スクロール位置の計算
	myscrolly += ( height + margin );
	
	//アニメーション的にスクロールさせる。
	$('html,body').animate({ scrollTop: myscrolly }, 'slow');
}


////////////////////////////////////////////////////////////////////
//もう一度やるをクリックした場合の処理
////////////////////////////////////////////////////////////////////
function procReset()
{
	$('html,body').animate({ scrollTop: 200},'slow' );
	
	$("#yesorno").fadeOut(
		"slow", 
		function() {
			//一度、表示した要素を全て消す。
			$("#yesorno > *").remove();
			
			//その後、消した要素をajexにて再度取り込む。
			//読み込み完了後、再度、各イベントを再登録する。
			var html = $("#yesorno");
			html.load( 
				"dgns4.html #yesorno > *",
				null,
				function(){
					$("#yesorno p.select a").one( "click", procYesOrNo ); 
					$("#yesorno div.yn-result button").click( procReset );
					
					//再度読み込んだ内容をフェードイン的に表示させる。
					html.fadeIn( "slow" );
				}
			);
		}
	);
}
