/**
 * 
 * 各ページ共通のエフェクト
 * 
 */
$(function(){
	
	// form field text
	$('.autoclear').autoclear();
	
	// scroll
	$('.pagetop').click(function(){ scrollTo("#gbHeader"); return false; });
	
	// roll over effects
	rollOverImage();
	rollOverImageAlpha();
	
	// rollover for header global navigation
	$('#gbHeader nav ul li img').each(function(){
		$(this).hover(function () {
			$(this).stop(true).animate({'opacity':0}, 200, 'swing');
		}, function () {
			$(this).stop(true).animate({'opacity':1}, 400, 'swing');
		});
	});
	
	// rollover for right side second navigation
	$('#gbAsideMenu ul li a').hover(function () {
		$(this).stop(true).animate({'background-color':'#ECFAFE'}, 100, 'swing');
	}, function () {
		$(this).stop(true).animate({'background-color':'#FFFFFF'}, 400, 'swing');
	});
	
	// back to top
	$("#backtop").hide();
	$(window).scroll(function () {
		if ($(this).scrollTop() > 400) {
			$('#backtop').fadeIn();
		} else {
			$('#backtop').fadeOut();
		}
	});
	$('#backtop a').click(function () { scrollTo('#gbHeader'); return false; });
});

/*======================================================
scroll to the id
======================================================*/
function scrollTo(id){
	$('html, body').animate({scrollTop:$(id).offset().top}, 1500, "jswing");
}

/*======================================================
ロールオーバーイメージ 画像切り替え
======================================================*/
function rollOverImage() {
	var preLoad = new Object();
	$('img.rollOver, input.rollOver').not("[src*='_on.']").each(function(){
		var imgSrc = this.src;
		var fType = imgSrc.substring(imgSrc.lastIndexOf('.'));
		var imgName = imgSrc.substr(0, imgSrc.lastIndexOf('.'));
		var imgOver = imgName + '_on' + fType;
		preLoad[this.src] = new Image();
		preLoad[this.src].src = imgOver;
		$(this).hover(
			function (){ this.src = imgOver; },
			function (){ this.src = imgSrc;  }
		);
	});
}

/*======================================================
ロールオーバーイメージ 透明度切り替え
======================================================*/
function rollOverImageAlpha() {
	$('img.rollOverAlpha, input.rollOverAlpha').each(function(){
		$(this).hover(
			function (){ $(this).addClass("alphaImage"); },
			function (){ $(this).removeClass("alphaImage"); }
		);
	});
}




