
var sendFlag = null;

	//contactForm
	//------------------------------------------------------------------------------*/
	function formChecker(){
		if(sendFlag==="OK"){return true;}
		$("div#formAlert").hide();
		var form = $("form[name='contactForm']");
		//$("input[name='confirm']").attr("disabled","disabled").css("opacity", 0.2);

			var alertText = [];
			var requiredMax = $("input.required, textarea.required").size();
			var successSend = function () {return true};
			$("input.required, textarea.required").each(function (){
				if($(this).attr("value")==="") {
					alertText.push($(this).parent().prev().text().replace("（必須）",""));
				}
			});
			
			var w = $(window);
			var numChildren = $("body *").size();
			$("div#formAlert").css({"width":w.width(),"height":w.height(),"z-index":numChildren});
			var openAlertWindow = function (target) {
				$("div#formAlert").fadeTo(300, 1, function (){
					$("div#smallWindow").fadeTo(300,1);
					//close
					target.bind("click",function (){
						$("div#formAlert").fadeTo(300,0,function (){
							$("div#formAlert").unbind("click");
							$("div#formAlert").hide();
							$("div#smallWindow div.msg").empty();
							})
						})
				});
			}
			
			if(alertText.length!=0) {
					//required error
					$("div#smallWindow p.alert").html("<strong>"+alertText.length+"件の未入力の項目があります！</strong>");
					$("div#smallWindow p.confirm").css("display","none");
					$("div#smallWindow p.alert").css("display","block");
					$("div#smallWindow div.msg").append("<ol></ol>");
					for(var n=0; n<alertText.length; n++){$("div#smallWindow div.msg ol").append("<li>"+alertText[n]+"</li>")};
					$("div#smallWindow div.msg").append('<p class="buttons"><img class="backToform" src="img/btn_back.png" alt="戻る"></p>');
					$("div#smallWindow div.msg p.buttons img").hover(function (){$(this).fadeTo(300,0.6)},function (){$(this).fadeTo(300,1)});
					openAlertWindow($("div#formAlert"));
				} //required error
				else {
					$("div#smallWindow p.confirm").html("この内容で送信します。よろしいですか？");
					$("div#smallWindow p.alert").css("display","none");
					$("div#smallWindow p.confirm").css("display","block");
					$("div#smallWindow div.msg").append("<table></table>");
					$("form[name='contactForm'] input:not(input[name='confirm']), form[name='contactForm'] textarea").each(function (){
						$("div#smallWindow div.msg table").append("<tr><th>"+$(this).parent().prev().text().replace("（必須）","")+"</th><td>"+$(this).attr("value")+"</td></tr>");
					});
					$("div#smallWindow div.msg").append('<p class="buttons"><img class="backToform" src="img/btn_back.png" alt="戻る"><img name="submit" type="image" class="AllSubmit" src="img/btn_send.jpg" alt="送信"></p>');
					$("div#smallWindow div.msg p.buttons img").hover(function (){$(this).fadeTo(300,0.6)},function (){$(this).fadeTo(300,1)});
					openAlertWindow($("p.buttons img.backToform"));
					$("p.buttons .AllSubmit").click(function(){sendFlag="OK";form.submit()});
				}
		return false;	
	};



$(function (){
	
	// navigationHelper
	//------------------------------------------------------------------------------*/
	(function navigationHelper() {
		var showGlobalHelp = function (e) {
				e.stopPropagation();
				$(this).find("span").show(200);
			}
		
		var hideGlobalHelp = function (e) {
				e.stopPropagation();
				$(this).find("span").hide(200);
			}
		
		$("nav#global ul li a").hover(showGlobalHelp, hideGlobalHelp);
	})();
	
	//currentPage to navigation
	//------------------------------------------------------------------------------*/
	(function currentNavigation(){
		var fileName = location.pathname.split("/");
		$("nav#global ul li a img").each(function(){
				if($(this).attr("alt").toLowerCase() === fileName[fileName.length-2]) {
					var imgFileName = "nav_"+fileName[fileName.length-2]+"_over";
					$(this).attr("src","../common/img/"+imgFileName+".png");
				}
			});
		})();
	
	//searchTypeSwitch
	//------------------------------------------------------------------------------*/
	(function searchTypeSwitcher(){
	var searchType = 0;
	$("aside#search ul.searchTypes li:nth-child(2)").fadeTo(0, 0.2);
	$("aside#search ul.searchTypes li").bind("click", function (){
		$("aside#search ul.searchTypes li").each(function (){$(this).fadeTo(0, 0.2)});
			if($(this).index() === 0) {
				searchType = "DM";
			}else{
				searchType = "";
			}
			$(this).fadeTo(200, 1);
			$("aside#search input[name='RD']").attr("value",searchType);
		});
	})();
		
	//topVisualFadeIn
	//------------------------------------------------------------------------------*/
	(function topVisualFadeIn(){
		$("#keyvisual img").hide();
		$("#keyvisual img").fadeTo(1000,1, function (){
			$("#keyvisual").empty();
			var img = new Image();
			img.src="common/img/top_kv.png";
			$("#keyvisual").append(img);
		});
	})();
		
	//topNews used Ajax
	//------------------------------------------------------------------------------*/
	(function getArchiveToNews(){
		var nEntry = 8;
		var fileName = $("div#main").find("section#news");
			if(fileName.length!==0){// page is Top
				var element = $("<ul class='empty'></ul>");
				element.load("./archive/index.html section#news ul li", function (responseText, status, XMLHttpRequest){
					var articles = [];
					$(responseText).find("div#main div ul li").each(function (){
						articles.push($(this).get(0));
						});
						for(var i=0; i<Math.min(articles.length, nEntry); i++) {
							//$(articles[i]).css("opacity", 0);
							$("div#main section#news ul").append(articles[i]);
							//$(articles[i]).fadeTo(200*i, 1);
						}
						delete element;
					});
			};
	})();
	
	//side common used Ajax
	//------------------------------------------------------------------------------*/
	
	(function (){
			$.ajax({
					url: "/common/temp/side.tmp",
					cache: false,
					success: function (html){
							$("div#side").append(html);
						}
				});
		})()
	
	
	
	
	
	
	
	
	
	
	
});




