/* --------------------------------------------------------------------------------------
   ロールオーバー
--------------------------------------------------------------------------------------- */

$(function(){
	$("#index ul a img,.side ul a img").mouseover(function(){
		$(this)
			.stop(false,true)
			.fadeTo("normal",0);
	});
	
	$("#index ul a img,.side ul a img").mouseout(function(){
		$(this)
			.stop(false,true)
			.fadeTo("fast",1);
	});
});

/* --------------------------------------------------------------------------------------
   ページトップ
--------------------------------------------------------------------------------------- */

$(function(){
	if ($.browser.opera ? document.compatMode == "BackCompat" ? "body" : "html" :"html,body") {
		$("#pagetop").click(function(){
			$(this).blur();
			$("html").animate({ scrollTop: 0 }, "slow");
		});
	}
	
	if (! $.browser.opera) {
		$("#pagetop").click(function(){
			$(this).blur();
			$("html,body").animate({ scrollTop: 0 }, "slow");
		});
	}
});	

/* --------------------------------------------------------------------------------------
   ページ内リンクスクロール
--------------------------------------------------------------------------------------- */

$(function(){
	if ($.browser.opera ? document.compatMode == "BackCompat" ? "body" : "html" :"html,body") {
		$("a[href^=#]").click(function(){
			var target;
			target = $( $(this).attr("href") );
				if (target.length == 0) {
					return;
				}
			$("html").animate({scrollTop: target.offset().top},"slow");
			return false;
		});
	}
	
	if (! $.browser.opera) {
		$("a[href^=#]").click(function(){
		var target;
		target = $( $(this).attr("href") );
			if (target.length == 0) {
				return;
			}
		$("html, body").animate({scrollTop: target.offset().top},"slow");
		return false;
		});
	}
});

function setYear(){
	var d_obj = new Date();
	document.write(d_obj.getFullYear());
}
function getMonth(){
	var d_obj = new Date();
	document.write(d_obj.getMonth()+1);
}
function getDate(){
	var d_obj = new Date();
	document.write(d_obj.getDate());
}
function afterMonth(){
	var d_obj = new Date();
	d_obj.setMonth(d_obj.getMonth()+4);
	document.write(d_obj.getMonth());
}

function init(){
	changeRadio();
	setFlash();
	head_line_ifo();
	switchConsent();
}
if (window.addEventListener){
	window.addEventListener("load",init,false);
}else if(window.attachEvent){
	window.attachEvent("onload",init);
}else{
	window.onload = init;
}
function changeRadio(){

	if(!document.getElementById("contact")){
		return;
	}

	var span = document.createElement("span");
	span.className = "must";
	span.style.color = "red";
	span.innerHTML = "※";
	
	var typeValue = "";
	
	
	if($("#type_entry")[0].checked == true){
	
		$(".formbody")[0].getElementsByTagName("dt")[4].appendChild(span.cloneNode(true));
		$(".formbody")[0].getElementsByTagName("dt")[5].appendChild(span.cloneNode(true));
	
	}
	
	if($("#type_entry_reserve")[0].checked == true || $("#type_reserve")[0].checked == true){
		$(".formbody")[0].getElementsByTagName("dt")[4].appendChild(span.cloneNode(true));
		$(".formbody")[0].getElementsByTagName("dt")[5].appendChild(span.cloneNode(true));
		$(".formbody")[0].getElementsByTagName("dt")[6].appendChild(span.cloneNode(true));
		$(".formbody")[0].getElementsByTagName("dt")[7].appendChild(span.cloneNode(true));
	}
	

	$("#type_entry")[0].onclick = function(){
		resetMust();
		if(typeValue != this.value){
			typeValue = this.value;
			$(".formbody")[0].getElementsByTagName("dt")[4].appendChild(span.cloneNode(true));
			$(".formbody")[0].getElementsByTagName("dt")[5].appendChild(span.cloneNode(true));
		}
	}

	$("#type_entry_reserve")[0].onclick = $("#type_reserve")[0].onclick = function(){
		resetMust();
		if(typeValue != this.value){
			typeValue = this.value;
			$(".formbody")[0].getElementsByTagName("dt")[4].appendChild(span.cloneNode(true));
			$(".formbody")[0].getElementsByTagName("dt")[5].appendChild(span.cloneNode(true));
			$(".formbody")[0].getElementsByTagName("dt")[6].appendChild(span.cloneNode(true));
			$(".formbody")[0].getElementsByTagName("dt")[7].appendChild(span.cloneNode(true));
		}
	}

	$("#type_other")[0].onclick = function(){
		resetMust();
	}
}
function resetMust(){
	
	var mustList = $(".must");
	var loopTime = mustList.length;
	for(i=0;i<loopTime;i++){
		mustList[i].parentNode.removeChild(mustList[i]);
	}
}
function setFlash(){

	if(!document.getElementById("index")){
		return;
	}
	if(navigator.userAgent.indexOf("iPad") != -1 || navigator.userAgent.indexOf("iPhone") != -1){
		var img = document.createElement("img");
		img.src = "./images/sky05.jpg";
		img.alt = "羽田タートルスカイフィールド";
		img.width = "710";
		img.height = "255";
		var obj = document.getElementById("index").getElementsByTagName("object")[0];
		obj.parentNode.replaceChild(img,obj);
		return;
	}


}

function head_line_ifo(){
	
	var header = document.getElementById("header");
	header.style.position = "relative";
	
	var span = document.createElement("span");
	span.style.position = "absolute";
	span.style.left = "10px";
	span.style.top = "93px";
	span.style.lineHeight = "1.2";
	span.style.color = "#0a0aff";
	span.style.fontWeight = "bold";
	span.style.fontSize = "16px";
	span.innerHTML = '11月29日(火)リニューアルOPEN!<br><span style="font-size:10px;">※一般貸出予約受付を再開いたしました。</span>';
	
	header.insertBefore(span,header.getElementsByTagName("a")[0]);
}
function switchConsent(){
	
	if(!document.getElementById("agree")){
		return;
	}
	
	document.getElementById("agree").onclick = function(){
		target = document.getElementById("submit").getElementsByTagName("input")[0];
		target.id = "able";
	}
	document.getElementById("disagree").onclick = function(){
		target = document.getElementById("submit").getElementsByTagName("input")[0];
		target.id = "disable";
	}

}

function consentCheck(){

	if(document.getElementById("agree").checked){
		return true;
	}else{
		alert("ご予約をいただくには「個人情報の取扱いについての同意」に同意いただく必要がございます。");
		return false;
	}

}
