// JavaScript Document
$(document).ready(function(){
	rollOver();
	pageTop();
	tabChanger();
});

/*	ロールオーバー
-------------------------------------------------------------------------- */
function rollOver() {
	$("img[src*='_off.']").hover( setRollOver, setRollOut );
}

function setRollOver() {
	$(this).attr("src", $(this).attr("src").replace("_off.", "_on."));
}
function setRollOut() {
	$(this).attr("src", $(this).attr("src").replace("_on.", "_off."));
}

/*	スムーズスクロール
-------------------------------------------------------------------------- */
function pageTop() {
	var speed = 700;
	$("a.pn[href^='#']").click(function() {
		var target = $(this).attr('href').substr(1);
		var targetY = 0;
		var h = Math.max( document.body.clientHeight , document.body.scrollHeight );  
		h = Math.max( h , document.documentElement.scrollHeight );  
		h = Math.max( h , document.documentElement.clientHeight );
		var inH = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
		if(target != '') {
			targetY = $("*[name='"+target+"']").offset().top;
			if(targetY+inH > h) targetY = h-inH;
		}
		//if($('html').scrollTop() == 0) {
			//alert('test');
			$('html').animate({scrollTop:targetY}, speed, "easeInOutSine");
	//	} else{
			$('body').animate({scrollTop:targetY}, speed, "easeInOutSine");
		//}
		return false;
	});
}

function tabChanger() {
	$(".tabBox").each( function() {
		$(".tabCont").hide().filter(":first").show();
		$(".tabMenu a").click( function() {
			var index = $(".tabMenu a").index(this);
			$(".tabCont").hide().filter(":eq("+index+")").show();
			$(".tabMenu a").find("img").bind("mouseenter", setRollOver).bind("mouseleave", setRollOut).each( function() {
				$(this).attr("src", $(this).attr("src").replace("_on.", "_off.") );
			} );
			$(this).find("img").attr("src", $(this).find("img").attr("src").replace("_off.", "_on.") ).unbind("mouseenter").unbind("mouseleave");
			return false;
		} ).filter(":first").find("img").attr("src", $(".tabMenu a:first img").attr("src").replace("_off.", "_on.") ).unbind("mouseenter").unbind("mouseleave");
	} );
}
