$(function(){

	/* 検索ボタンマウスオーバー */
	$("#header :image.submit").mouseover(function(){
		$(this).attr("src","/common/images/btn_search_on.png");
	}).mouseout(function(){
		$(this).attr("src","/common/images/btn_search.png");
	});


	/* IE6のpng24の透過を有効に
	if($.browser.msie && $.browser.version==6) {
		DD_belatedPNG.fix('.home h2 img');
	} */

	/* IEの半透明を有効に */
	if($.browser.msie && $.browser.version==6) {
		$('.home h2 img').fixPng();
	}

	/* デフォルトで消しているBrandNewsのemを表示 */
	$("div.box em").css({
		display:"inline"
	});
	if($.browser.msie) { // IEでの実行タイミングの違いによるズレを解消
		$("div.box a:empty + em").css({
			marginTop:"3px"
		});
	}

	/* エントリーボックス内の画像投稿がない場合の代替画像 */
	$("#general .boxYu .entryWrapper a:empty:first-child, #yu .boxEntry a:empty:first-child, #yu .boxEntry2 a:empty:first-child").prepend("<img src='/common/images/noimage_yu.png'>");
	$("#general .boxKisara .entryWrapper a:empty:first-child, #kisara .boxEntry a:empty:first-child, #kisara .boxEntry2 a:empty:first-child").prepend("<img src='/common/images/noimage_kisara.png'>");
	$("#general .boxShoten .entryWrapper a:empty:first-child, #shoten .boxEntry a:empty:first-child, #shoten .boxEntry2 a:empty:first-child").prepend("<img src='/common/images/noimage_shoten.png'>");
	$("#general .boxSabou .entryWrapper a:empty:first-child, #sabou .boxEntry a:empty:first-child, #sabou .boxEntry2 a:empty:first-child").prepend("<img src='/common/images/noimage_sabou.png'>");
	$("#general .box2to9 .entryWrapper a:empty:first-child, #2to9 .boxEntry a:empty:first-child, #2to9 .boxEntry2 a:empty:first-child").prepend("<img src='/common/images/noimage_2to9.png'>");
	$("#general .presidentEntry01 a:empty:first-child, #general .presidentEntry02 a:empty:first-child, #general .boxBlog02 .entryWrapper a:empty:first-child, #general .boxBlog03 .entryWrapper a:empty:first-child").prepend("<img src='/common/images/noimage_general.png'>");


	/* エントリーボックス最下部のボーダーは消す */
	$(".boxYu .entryWrapper:last, .boxKisara .entryWrapper:last, .boxShoten .entryWrapper:last, .boxSabou .entryWrapper:last").css({
		borderBottom:"none",
		paddingBottom:"0"
	});


	/* エントリーボックス下部リンク */
	$("div.moreLink a").hover(function(){
		$("img",$(this)).animate({
			marginRight:"-6px"
		},100,"easeOutExpo");
	},function(){
		$("img",$(this)).animate({
			marginRight:"-64px"
		},10,"easeOutExpo");
	}).mouseup(function(){
		$("img",$(this)).animate({
			marginRight:"-64px"
		},10,"easeOutExpo");
	});


	/* ボックスの高さそろえる */
	$('.boxYu, .boxKisara, .boxShoten, .boxSabou').flatHeights();
	$('.boxPressRelease, .boxPublication, .boxRecruit').flatHeights();
	$('.boxBlog01, .boxBlog02, .boxBlog03, .box2to9').flatHeights();
	$('.boxEntry').flatHeights();
	$('.boxEntry2').flatHeights();


	/* 画像マウスオーバー */
	$("#sidebar h1 a img, #sidebar ul#globalNavi a img, #sidebar ul#relatedInfo a img, #sidebar ul#banners a img, .books a img, #footer a img, p.pagetop a img").mouseover(function(){
		$(this).fadeTo("fast",0.4);
	}).mouseout(function(){
		$(this).fadeTo("slow",1);
	}).mouseup(function(){
		$(this).fadeTo("slow",1);
	});

	$("#yu #mainvisual a img,#kisara #mainvisual a img,#shoten #mainvisual a img,#nitokyu #mainvisual a img,#sabou #mainvisual a img,div.columnBlog div.columnLeft div.blogEntry a img,a.trimmedScroll img").mouseover(function(){
		$(this).fadeTo("fast",0.6);
	}).mouseout(function(){
		$(this).fadeTo("slow",1);
	}).mouseup(function(){
		$(this).fadeTo("slow",1);
	});

	$(".box a img").mouseover(function(){
		$(this).fadeTo("fast",0.7);
	}).mouseout(function(){
		$(this).fadeTo("slow",1);
	}).mouseup(function(){
		$(this).fadeTo("slow",1);
	});
	$(".box h2 a img").unbind("mouseover");


	/* サイドバー関連情報マウスオーバー
	$("#sidebar ul#relatedInfo li a").hover(function(){
		$(this).prepend("<img src='/common/images/related_info_on.png' style='position:absolute;z-index:1;left:0px;display:none;'>");
		$("img:first",$(this)).fadeTo("slow",0.8);
	},function(){
		$("img:not(:last)",$(this)).fadeOut("fast");
		// $("img:last",$(this)).fadeTo("fast",1);
	}).mouseup(function(){
		$("img:not(:last)",$(this)).fadeOut("fast");
		// $("img:last",$(this)).fadeTo("fast",1);
	}); */

	/* ドロップシャドウ
	if(!($.browser.msie)) {
	$(".columnAll h3,.columnAll h4").dropShadow({
		left:0.1,
		top:0.1,
		blur:0,
		opacity:0.3,
		color:"#000"
	});
	$(".box dl a,.box dl dd,.box ul li a").dropShadow({
		left:0,
		top:0,
		blur:0.9,
		opacity:2,
		color:"#fff"
	});
	} */

	/* ホームブランドメニュー */
	jQuery.preloadImages = function(){
		for(var i = 0; i<arguments.length; i++){
			jQuery("<img>").attr("src", arguments[i]);
		}
	};
	$.preloadImages("/images/header_yu_on.png","/images/header_kisara_on.png","/images/header_shoten_on.png","/images/header_sabou_on.png");

	/* IE7の場合 */
	if ($.browser.msie && !($.browser.version == 6)) {
	$("h2#yuNavi a").mouseover(function(){
		$(this).prepend("<img src='/images/header_yu_on.png'>");
		$("img:first",$(this)).animate({
			marginLeft:"-160px"
		},7000,"easeOutCubic");
	}).mouseout(function(){
		$("img",$(this)).remove();
		$(this).append("<img src='/images/header_yu.png'>");
	}).click(function(){
		$("img:last",$(this)).remove();
		$(this).append("<img src='/images/header_yu.png'>");
		location.href = "/yu/";
	});

	$("h2#kisaraNavi a").mouseover(function(){
		$(this).prepend("<img src='/images/header_kisara_on.png'>");
		$("img:first",$(this)).animate({
			marginLeft:"-160px"
		},7000,"easeOutCubic");
	}).mouseout(function(){
		$("img",$(this)).remove();
		$(this).append("<img src='/images/header_kisara.png'>");
	}).click(function(){
		$("img:last",$(this)).remove();
		$(this).append("<img src='/images/header_kisara.png'>");
		location.href = "/kisara/";
	});

	$("h2#shotenNavi a").mouseover(function(){
		$(this).prepend("<img src='/images/header_shoten_on.png'>");
		$("img:first",$(this)).animate({
			marginLeft:"-160px"
		},7000,"easeOutCubic");
	}).mouseout(function(){
		$("img",$(this)).remove();
		$(this).append("<img src='/images/header_shoten.png'>");
	}).mousedown(function(){
		$("img:last",$(this)).remove();
		$(this).append("<img src='/images/header_shoten.png'>");
		location.href = "/shoten/";
	});

	$("h2#sabouNavi a").mouseover(function(){
		$(this).prepend("<img src='/images/header_sabou_on.png'>");
		$("img:first",$(this)).animate({
			marginLeft:"-160px"
		},7000,"easeOutCubic");
	}).mouseout(function(){
		$("img",$(this)).remove();
		$(this).append("<img src='/images/header_sabou.png'>");
	}).mousedown(function(){
		$("img:last",$(this)).remove();
		$(this).append("<img src='/images/header_sabou.png'>");
		location.href = "/sabou/";
	});

	}

	/* IE以外の場合 */
	if (!($.browser.msie)) {
	$("h2#yuNavi a").mouseover(function(){
		$(this).prepend("<img src='/images/header_yu_on.png'>");
		$("img:first",$(this)).animate({
			marginLeft:"-160px"
		},7000,"easeOutCubic");
	}).mouseout(function(){
		$("img",$(this)).remove();
		$(this).append("<img src='/images/header_yu.png'>");
	}).click(function(){
		$("img:first",$(this)).remove();
	});

	$("h2#kisaraNavi a").mouseover(function(){
		$(this).prepend("<img src='/images/header_kisara_on.png'>");
		$("img:first",$(this)).animate({
			marginLeft:"-160px"
		},7000,"easeOutCubic");
	}).mouseout(function(){
		$("img",$(this)).remove();
		$(this).append("<img src='/images/header_kisara.png'>");
	}).click(function(){
		$("img:first",$(this)).remove();
	});

	$("h2#shotenNavi a").mouseover(function(){
		$(this).prepend("<img src='/images/header_shoten_on.png'>");
		$("img:first",$(this)).animate({
			marginLeft:"-160px"
		},7000,"easeOutCubic");
	}).mouseout(function(){
		$("img",$(this)).remove();
		$(this).append("<img src='/images/header_shoten.png'>");
	}).click(function(){
		$("img:first",$(this)).remove();
	});

	$("h2#sabouNavi a").mouseover(function(){
		$(this).prepend("<img src='/images/header_sabou_on.png'>");
		$("img:first",$(this)).animate({
			marginLeft:"-160px"
		},7000,"easeOutCubic");
	}).mouseout(function(){
		$("img",$(this)).remove();
		$(this).append("<img src='/images/header_sabou.png'>");
	}).click(function(){
		$("img:first",$(this)).remove();
	});

	}



	/* ボックスマウスオーバー
	$(".boxYu").hover(function(){
		$(this).css("background-image","url(/common/images/bg_box.png)");
		$("h2#yuNavi").css("background-image","url(/common/images/bg_box.png)");
		$("h2#yuNavi a").prepend("<img src='images/header_yu_logo.png'>");
		$("h2#yuNavi a img:last").css("visibility","hidden");
	},function(){
		$(this).css("background-image","url(/common/images/bg_boxyu.png)");
		if($.browser.msie && $.browser.version<7) {
			$(this).css("background-image","url(/common/images/bg_boxyu.png)");
		}
		$("h2#yuNavi").css("background-image","url(/common/images/bg_boxyu.png)");
		$("h2#yuNavi a img:not(:last)").remove();
		$("h2#yuNavi a img:last").css("visibility","visible");
	}).click(function(){
		$(this).css("background-image","url(/common/images/bg_boxyu.png)");
		if($.browser.msie && $.browser.version<7) {
			$(this).css("background-image","url(/common/images/bg_boxyu.png)");
		}
	});

	$(".boxKisara").mouseover(function(){
		$(this).css("background-image","url(/common/images/bg_box.png)");
		$("h2#kisaraNavi").css("background-image","url(/common/images/bg_box.png)");
		$("h2#kisaraNavi a").prepend("<img src='images/header_kisara_logo.png'>");
		$("h2#kisaraNavi a img:last").css("visibility","hidden");
	}).mouseout(function(){
		$(this).css("background-image","url(/common/images/bg_boxkisara.png)");
		if($.browser.msie && $.browser.version<7) {
			$(this).css("background-image","url(/common/images/bg_boxkisara.png)");
		}
		$("h2#kisaraNavi").css("background-image","url(/common/images/bg_boxkisara.png)");
		$("h2#kisaraNavi a img:not(:last)").remove();
		$("h2#kisaraNavi a img:last").css("visibility","visible");
	}).click(function(){
		$(this).css("background-image","url(/common/images/bg_boxkisara.png)");
		if($.browser.msie && $.browser.version<7) {
			$(this).css("background-image","url(/common/images/bg_boxkisara.png)");
		}
	});

	$(".boxShoten").mouseover(function(){
		$(this).css("background-image","url(/common/images/bg_box.png)");
		$("h2#shotenNavi").css("background-image","url(/common/images/bg_box.png)");
		$("h2#shotenNavi a").prepend("<img src='images/header_shoten_logo.png'>");
		$("h2#shotenNavi a img:last").css("visibility","hidden");
	}).mouseout(function(){
		$(this).css("background-image","url(/common/images/bg_boxshoten.png)");
		if($.browser.msie && $.browser.version<7) {
			$(this).css("background-image","url(/common/images/bg_boxshoten.png)");
		}
		$("h2#shotenNavi").css("background-image","url(/common/images/bg_boxshoten.png)");
		$("h2#shotenNavi a img:not(:last)").remove();
		$("h2#shotenNavi a img:last").css("visibility","visible");
	}).click(function(){
		$(this).css("background-image","url(/common/images/bg_boxshoten.png)");
		if($.browser.msie && $.browser.version<7) {
			$(this).css("background-image","url(/common/images/bg_boxshoten.png)");
		}
	});

	$(".boxSabou").mouseover(function(){
		$(this).css("background-image","url(/common/images/bg_box.png)");
		$("h2#sabouNavi").css("background-image","url(/common/images/bg_box.png)");
		$("h2#sabouNavi a").prepend("<img src='images/header_sabou_logo.png'>");
		$("h2#sabouNavi a img:last").css("visibility","hidden");
	}).mouseout(function(){
		$(this).css("background-image","url(/common/images/bg_boxsabou.png)");
		if($.browser.msie && $.browser.version<7) {
			$(this).css("background-image","url(/common/images/bg_boxsabou.png)");
		}
		$("h2#sabouNavi").css("background-image","url(/common/images/bg_boxsabou.png)");
		$("h2#sabouNavi a img:not(:last)").remove();
		$("h2#sabouNavi a img:last").css("visibility","visible");
	}).click(function(){
		$(this).css("background-image","url(/common/images/bg_boxsabou.png)");
		if($.browser.msie && $.browser.version<7) {
			$(this).css("background-image","url(/common/images/bg_boxsabou.png)");
		}
	});

	$("#yu .boxEntry, #yu .boxEntry2").mouseover(function(){
		$(this).css("background-image","url(/common/images/bg_box.png)");
	}).mouseout(function(){
		$(this).css("background-image","url(/common/images/bg_boxyu.png)");
		if($.browser.msie && $.browser.version<7) {
			$(this).css("background-image","none");
		}
	}).click(function(){
		$(this).css("background-image","url(/common/images/bg_boxyu.png)");
		if($.browser.msie && $.browser.version<7) {
			$(this).css("background-image","none");
		}
	});

	$("#kisara .boxEntry, #kisara .boxEntry2").mouseover(function(){
		$(this).css("background-image","url(/common/images/bg_box.png)");
	}).mouseout(function(){
		$(this).css("background-image","url(/common/images/bg_boxkisara.png)");
		if($.browser.msie && $.browser.version<7) {
			$(this).css("background-image","none");
		}
	}).click(function(){
		$(this).css("background-image","url(/common/images/bg_boxkisara.png)");
		if($.browser.msie && $.browser.version<7) {
			$(this).css("background-image","none");
		}
	});

	$("#shoten .boxEntry, #shoten .boxEntry2").mouseover(function(){
		$(this).css("background-image","url(/common/images/bg_box.png)");
	}).mouseout(function(){
		$(this).css("background-image","url(/common/images/bg_boxshoten.png)");
		if($.browser.msie && $.browser.version<7) {
			$(this).css("background-image","none");
		}
	}).click(function(){
		$(this).css("background-image","url(/common/images/bg_boxshoten.png)");
		if($.browser.msie && $.browser.version<7) {
			$(this).css("background-image","none");
		}
	});

	$("#sabou .boxEntry, #sabou .boxEntry2").mouseover(function(){
		$(this).css("background-image","url(/common/images/bg_box.png)");
	}).mouseout(function(){
		$(this).css("background-image","url(/common/images/bg_boxsabou.png)");
		if($.browser.msie && $.browser.version<7) {
			$(this).css("background-image","none");
		}
	}).click(function(){
		$(this).css("background-image","url(/common/images/bg_boxsabou.png)");
		if($.browser.msie && $.browser.version<7) {
			$(this).css("background-image","none");
		}
	});

	$(".boxBlog01,.boxBlog02,.boxBlog03,.boxPressRelease,.boxPublication,.boxRecruit").mouseover(function(){
		$(this).css("background-image","url(/common/images/bg_boxgeneral.png)");
	}).mouseout(function(){
		$(this).css("background-image","url(/common/images/bg_box.png)");
		if($.browser.msie && $.browser.version<7) {
			$(this).css("background-image","none");
		}
	}).click(function(){
		$(this).css("background-image","url(/common/images/bg_box.png)");
		if($.browser.msie && $.browser.version<7) {
			$(this).css("background-image","none");
		}
	});
 */


	/* コーポレートナビの二階層目表示／非表示切換え
	var naviConfig = [
	    { rule:"/corporate/", selector:"#recruit,#b2b" },
	    { rule:"/b2b/", selector:"#corporate,#recruit" },
	    { rule:"/recruit/", selector:"#b2b,#corporate" }
	];
	(function(config){
	    for(var i=0;i<config.length;i++){
	        if( location.href.match(config[i].rule) ){
	            $(config[i].selector).addClass("noActive");
	            return;
	        }
	    }
	})( naviConfig );
 */


	/* コーポレートナビの二階層目表示／非表示切換え */
		$("#company").css("display","inline");
		$("#company_noScript").css("display","none");

	if(location.href.match("/corporate/")){
			$("#b2b").remove();
			$("#recruit").remove();
			$("#company").remove();
		} else if(location.href.match("/b2b/")){
			$("#corporate").remove();
			$("#recruit").remove();
			$("#company").remove();
		} else if(location.href.match("/recruit/")){
			$("#corporate").remove();
			$("#b2b").remove();
			$("#company").remove();
		} else if(location.href.match("/company/")){
			$("#corporate").remove();
			$("#recruit").remove();
			$("#b2b").remove();
		} else {
			$("#corporate").remove();
			$("#b2b").remove();
			$("#recruit").remove();
			$("#company").remove();
		};


	/* アコーディオン */
	jQuery.preloadImages = function(){
		for(var i = 0; i<arguments.length; i++){
			jQuery("<img>").attr("src", arguments[i]);
		}
	};
	$.preloadImages("/common/images/arrow_plus_on.png","/common/images/arrow_minus.png","/common/images/arrow_minus_on.png");

	$(".accordionOpen > dt").css("cursor","pointer");
	$(".accordionOpen > dd").css("display","none");
	$(".accordionOpen > dt").mouseover(function(){
		$(this).css("color","#999");
		if($(this).next("dd").css("display")=="none"){
			$(this).css("background-image","url(/common/images/arrow_plus_on.png)");
		} else {
			$(this).css("background-image","url(/common/images/arrow_minus_on.png)");
		}
	});
	$(".accordionOpen > dt").mouseout(function(){
		$(this).css("color","#222");
		if($(this).next("dd").css("display")=="none"){
			$(this).css("background-image","url(/common/images/arrow_plus.png)");
		} else {
			$(this).css("background-image","url(/common/images/arrow_minus.png)");
		}
	});
	$(".accordionOpen > dt").click(function(){
		if($(this).next("dd").css("display")=="none"){
			$(this).next("dd").slideDown("normal");
			$(this).css("background-image","url(/common/images/arrow_minus.png)");
		} else {
			$(this).next("dd").slideUp("normal");
			$(this).css("background-image","url(/common/images/arrow_plus.png)");
		}
	});



	/* 問い合わせフォームバリデーション */
	$("form").submit(function(){
		//エラーの初期化
		$("p.error").remove();
		$("dl dd").removeClass("error")
		
		$(":text,textarea").filter(".validate").each(function(){
		
			//必須項目のチェック
			$(this).filter(".required").each(function(){
				if($(this).val()==""){
					$(this).parent().prepend("<p class='error'>必須項目です</p>");
				}
			});
			
			//数値のチェック
			$(this).filter(".number").each(function(){
				if(isNaN($(this).val())){
					$(this).parent().prepend("<p class='error'>数値のみ入力可能です</p>");
				}
			});
			
			//メールアドレスのチェック
			$(this).filter(".mail").each(function(){
				if($(this).val() && !$(this).val().match(/.+@.+¥..+/g)){
					$(this).parent().prepend("<p class='error'>メールアドレスの形式が異なります</p>");
				}
			});
		});
		
		//ラジオボタンのチェック
		$(":radio").filter(".validate").each(function(){
			$(this).filter(".required").each(function(){
				if($("input[name="+$(this).attr("name")+"]:checked").size()==0){
					$(this).parent().prepend("<p class='error'>選択して下さい</p>");
				}
			});
		});
		
		//チェックボックスのチェック
		$(".checkboxRequired").each(function(){
			if($(":checkbox:checked",this).size()==0){
				$(this).prepend("<p class='error'>選択して下さい</p>");
			}
		});
		
		//エラーの際の処理
		if($("p.error").size() > 0){
			$('html,body').animate({scrollTop: $("p.error:first").offset().top-40},'slow');
			$('p.error').parent().addClass("error");
			return false;
		}
	});

});


