// モーダルウィンドウ
$(function(){
	// $("dd").hide()
	$("body").append("<div id='glayLayer'>&nbsp;</div><iframe id='overLayer' frameborder='0' scrolling='no'></iframe>");
	
	$("#glayLayer").click(function(){
		$(this).hide();
		$("#overLayer").hide();
	});
	
	$("a.modalwin").click(function(){
		$("#glayLayer").show();
		$("#overLayer").show().attr("src",$(this).attr("href"));
		$('html,body').animate({ scrollTop: $("#pagetop").offset().top-40},'fast');
		return false;
	});
	
	var h = Math.max.apply( null, [document.body.clientHeight , document.body.scrollHeight, document.documentElement.scrollHeight, document.documentElement.clientHeight] );
	$("#glayLayer").css("height",h);
});


// lnaviのtoggle　トップページ用
$(function(){
	$("#lnavi dt.pulldown1t a").mouseover(function(){
	if($("#lnavi dt.pulldown1t+dd").css("display")=="none"){
		$(this).css({
		backgroundImage : "url(common/img/lnavi_bg_def_on.gif)",
		backgroundColor : "#023c70"
		});
	}else{
		$(this).css({
		backgroundImage : "url(common/img/lnavi_bg_ov.gif)",
		backgroundColor : "#014c8e"
		});
	}
	}).mouseout(function(){
	if($("#lnavi dt.pulldown1t+dd").css("display")=="none"){
		$(this).css({
		backgroundImage : "url(common/img/lnavi_bg_def.gif)",
		backgroundColor : "#014c8e"
		});
	}
	return false;
	});
	
	$("#lnavi dt.pulldown1t a").mouseover(function(){
	if($("#lnavi dt.pulldown1t+dd").css("display")=="none"){
		$(this).css({
		backgroundImage : "url(common/img/lnavi_bg_ov.gif)",
		backgroundColor : "#014c8e",
		borderBottom : "none"
		});
		$("#lnavi dt.pulldown1t+dd").slideDown("fast");
	}else{
		$(this).css({
		backgroundImage : "url(common/img/lnavi_bg_def.gif)",
		backgroundColor : "#014c8e",
		borderBottom : "1px solid #bfbfbf"
		});
		$("#lnavi dt.pulldown1t+dd").slideUp("fast");
	}
	return false;
	});
});

$(function(){
	$("#lnavi dt.pulldown2t a").mouseover(function(){
	if($("#lnavi dt.pulldown2t+dd").css("display")=="none"){
		$(this).css({
		backgroundImage : "url(common/img/lnavi_bg_def_on.gif)",
		backgroundColor : "#023c70"
		});
	}else{
		$(this).css({
		backgroundImage : "url(common/img/lnavi_bg_ov.gif)",
		backgroundColor : "#014c8e"
		});
	}
	}).mouseout(function(){
	if($("#lnavi dt.pulldown2t+dd").css("display")=="none"){
		$(this).css({
		backgroundImage : "url(common/img/lnavi_bg_def.gif)",
		backgroundColor : "#014c8e"
		});
	}
	});
	
	$("#lnavi dt.pulldown2t a").mouseover(function(){
	if($("#lnavi dt.pulldown2t+dd").css("display")=="none"){
		$(this).css({
		backgroundImage : "url(common/img/lnavi_bg_ov.gif)",
		backgroundColor : "#014c8e",
		borderBottom : "none"
		});
		$("#lnavi dt.pulldown2t+dd").slideDown("fast");
	}else{
		$(this).css({
		backgroundImage : "url(common/img/lnavi_bg_def.gif)",
		backgroundColor : "#014c8e",
		borderBottom : "1px solid #bfbfbf"
		});
		$("#lnavi dt.pulldown2t+dd").slideUp("fast");
	}
	return false;
	});
});


// lnaviのtoggle
$(function(){
	$("#lnavi dt.pulldown1 a").mouseover(function(){
	if($("#lnavi dt.pulldown1+dd").css("display")=="none"){
		$(this).css({
		backgroundImage : "url(../common/img/lnavi_bg_def_on.gif)",
		backgroundColor : "#023c70"
		});
	}else{
		$(this).css({
		backgroundImage : "url(../common/img/lnavi_bg_ov.gif)",
		backgroundColor : "#014c8e"
		});
	}
	}).mouseout(function(){
	if($("#lnavi dt.pulldown1+dd").css("display")=="none"){
		$(this).css({
		backgroundImage : "url(../common/img/lnavi_bg_def.gif)",
		backgroundColor : "#014c8e"
		});
	}
	return false;
	});
	
	$("#lnavi dt.pulldown1 a").mouseover(function(){
	if($("#lnavi dt.pulldown1+dd").css("display")=="none"){
		$(this).css({
		backgroundImage : "url(../common/img/lnavi_bg_ov.gif)",
		backgroundColor : "#014c8e",
		borderBottom : "none"
		});
		$("#lnavi dt.pulldown1+dd").slideDown("fast");
	}else{
		$(this).css({
		backgroundImage : "url(../common/img/lnavi_bg_def.gif)",
		backgroundColor : "#014c8e",
		borderBottom : "1px solid #bfbfbf"
		});
		$("#lnavi dt.pulldown1+dd").slideUp("fast");
	}
	return false;
	});
});

$(function(){
	$("#lnavi dt.pulldown2 a").mouseover(function(){
	if($("#lnavi dt.pulldown2+dd").css("display")=="none"){
		$(this).css({
		backgroundImage : "url(../common/img/lnavi_bg_def_on.gif)",
		backgroundColor : "#023c70"
		});
	}else{
		$(this).css({
		backgroundImage : "url(../common/img/lnavi_bg_ov.gif)",
		backgroundColor : "#014c8e"
		});
	}
	}).mouseout(function(){
	if($("#lnavi dt.pulldown2+dd").css("display")=="none"){
		$(this).css({
		backgroundImage : "url(../common/img/lnavi_bg_def.gif)",
		backgroundColor : "#014c8e"
		});
	}
	});
	
	$("#lnavi dt.pulldown2 a").mouseover(function(){
	if($("#lnavi dt.pulldown2+dd").css("display")=="none"){
		$(this).css({
		backgroundImage : "url(../common/img/lnavi_bg_ov.gif)",
		backgroundColor : "#014c8e",
		borderBottom : "none"
		});
		$("#lnavi dt.pulldown2+dd").slideDown("fast");
	}else{
		$(this).css({
		backgroundImage : "url(../common/img/lnavi_bg_def.gif)",
		backgroundColor : "#014c8e",
		borderBottom : "1px solid #bfbfbf"
		});
		$("#lnavi dt.pulldown2+dd").slideUp("fast");
	}
	return false;
	});
});

// captionのwidth取得
$(function(){
	$("#mainblock .photobox2 .left").each(function(){
		$("p.caption",this).css({
		width: $("img",this).width()+"px"
		});
	});
});

// imageboxのpのwidth取得
$(function(){
	$("#mainblock .imagebox").each(function(){
		$("p",this).css({
		width: 630-$("img",this).width()+"px"
		});
	});
});

// imagebox_rの.txtAreaのwidth取得
$(function(){
	$("#mainblock .imagebox_r").each(function(){
		$(".txtArea",this).css({
		width: 630-$("img",this).width()+"px"
		});
	});
});

// 最初の要素のみcss変更
$(function(){
	$("#gnavi li:first").css("padding-left","0px");
});


// リンクの点線を消す
$(function(){
	$("a").focus(function(){
		this.blur();
	});
});

// ロールオーバー　オーバー時の画像名に_onを付ける
$(function(){
	$("img.rollover").mouseover(function(){
		$(this).attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"));
	}).mouseout(function(){
		$(this).attr("src",$(this).attr("src").replace(/^(.+)_on(\.[a-z]+)$/, "$1$2"));
	}).mousedown(function(){
		$(this).attr("src",$(this).attr("src").replace(/^(.+)_on(\.[a-z]+)$/, "$1$2"));
	}).each(function(){
		$("<img>").attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"));
	});
});


// pngロールオーバー　オーバー時の画像名に_onを付ける
$(function(){
	$("img.pngrollover").each(function(){
		$("<img>").attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"));
	});
	
	if($.browser.msie && $.browser.version<7){
		$("img.pngrollover").each(function(){
			
			$(this)
				.data("src",$(this).attr("src"))
				.attr("src","/common/img/space.gif")
				.css("filter","progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+$(this).data("src")+"',sizingMethod='scale')");
			
		}).mouseover(function(){
			$(this).css("filter","progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+$(this).data("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2")+"',sizingMethod='scale')");
		}).mouseout(function(){
			$(this).css("filter","progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+$(this).data("src")+"',sizingMethod='scale')");
		});
		
	}else{
		$("img.pngrollover").mouseover(function(){
			$(this).attr("src",$(this).attr("src").replace(/^(.+)(\.[a-z]+)$/, "$1_on$2"));
		}).mouseout(function(){
			$(this).attr("src",$(this).attr("src").replace(/^(.+)_on(\.[a-z]+)$/, "$1$2"));
		}).mousedown(function(){
			$(this).attr("src",$(this).attr("src").replace(/^(.+)_on(\.[a-z]+)$/, "$1$2"));
		});
	}
});


// pngロールオーバーなし　imgクラス名png
$(function(){
	if($.browser.msie && $.browser.version<7){
		$("img.png").each(function(){
			
			$(this)
				.data("src",$(this).attr("src"))
				.attr("src","common/img/space.gif")
				// .attr("src","/common/img/space.gif")
				.css("filter","progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+$(this).data("src")+"',sizingMethod='scale')");
			
		})
	}
});


// ページトップへスクロール
/*--------------------------------------------------------------------------
 *  Smooth Scroller Script, version 1.0.1
 *  (c) 2007 Dezinerfolio Inc. <midart@gmail.com>
 *
 *  For details, please check the website : http://dezinerfolio.com/
 *
/*--------------------------------------------------------------------------*/

Scroller = {
	// control the speed of the scroller.
	// dont change it here directly, please use Scroller.speed=50;
	speed:10,

	// returns the Y position of the div
	gy: function (d) {
		gy = d.offsetTop
		if (d.offsetParent) while (d = d.offsetParent) gy += d.offsetTop
		return gy
	},

	// returns the current scroll position
	scrollTop: function (){
		body=document.body
	    d=document.documentElement
	    if (body && body.scrollTop) return body.scrollTop
	    if (d && d.scrollTop) return d.scrollTop
	    if (window.pageYOffset) return window.pageYOffset
	    return 0
	},

	// attach an event for an element
	// (element, type, function)
	add: function(event, body, d) {
	    if (event.addEventListener) return event.addEventListener(body, d,false)
	    if (event.attachEvent) return event.attachEvent('on'+body, d)
	},

	// kill an event of an element
	end: function(e){
		if (window.event) {
			window.event.cancelBubble = true
			window.event.returnValue = false
      		return;
    	}
	    if (e.preventDefault && e.stopPropagation) {
	      e.preventDefault()
	      e.stopPropagation()
	    }
	},
	
	// move the scroll bar to the particular div.
	scroll: function(d){
		i = window.innerHeight || document.documentElement.clientHeight;
		h=document.body.scrollHeight;
		a = Scroller.scrollTop()
		if(d>a)
			if(h-d>i)
				a+=Math.ceil((d-a)/Scroller.speed)
			else
				a+=Math.ceil((d-a-(h-d))/Scroller.speed)
		else
			a = a+(d-a)/Scroller.speed;
		window.scrollTo(0,a)
	  	if(a==d || Scroller.offsetTop==a)clearInterval(Scroller.interval)
	  	Scroller.offsetTop=a
	},
	// initializer that adds the renderer to the onload function of the window
	init: function(){
		Scroller.add(window,'load', Scroller.render)
	},

	// this method extracts all the anchors and validates then as # and attaches the events.
	render: function(){
		a = document.getElementsByTagName('a');
		Scroller.end(this);
		window.onscroll
	    for (i=0;i<a.length;i++) {
	      l = a[i];
	      if(l.href && l.href.indexOf('#') != -1 && ((l.pathname==location.pathname) || ('/'+l.pathname==location.pathname)) ){
	      	Scroller.add(l,'click',Scroller.end)
	      		l.onclick = function(){
	      			Scroller.end(this);
		        	l=this.hash.substr(1);
		        	 a = document.getElementsByTagName('a');
				     for (i=0;i<a.length;i++) {
				     	if(a[i].name == l){
				     		clearInterval(Scroller.interval);
				     		Scroller.interval=setInterval('Scroller.scroll('+Scroller.gy(a[i])+')',10);
						}
					}
				}
	      	}
		}
	}
}
// invoke the initializer of the scroller
Scroller.init();
