$(function() {
	//smartRollover

	var imgCount = 0;
	var images_pre = new Array();
	$('img[src*="_off."],input[src*="_off."]').each (function(){
		images_pre[imgCount] = new Image();
		images_pre[imgCount].src = $(this).attr("src").replace("_off.", "_on.");
		$(this).hover(
			function () {
				$(this).attr("src", $(this).attr("src").replace("_off.", "_on."));
			},
			function () {
				$(this).attr("src", $(this).attr("src").replace("_on.", "_off."));
			}
		);
		imgCount ++;
	});


	// external

	var notBlank = new Array("");

	var n = "";
	for (var i = 0; i < notBlank.length; i ++) if(notBlank[i]) n += ":not([href*='" + notBlank[i] + "'])";
	if(document.domain) n += ":not([href*='" + document.domain + "'])";

	$("a[rel='external'], a[href$='.pdf']").attr("target", "_blank");
	$("a[href^=http]"+n).attr("target", "_blank");



	// smoothScroll

	$('a[href^="#"], a[href^="' + location.pathname + '#"]').each (function(){
		var hash = this.hash;
		if(hash.length > 1 && !this['rel']){
			$(this).click(function() {
				smoothScroll(hash);
				return false;
			})
		}
	});



	// sideArea

	$('#sideArea a img').hover(
		function () {
			$(this).css('opacity', 0.7);
		},
		function () {
			$(this).css('opacity', 1);
		}
	);
	$('#sideSearch li:nth-child(3n)').addClass('right');
	$('#sideSearch > dl:last').addClass('last');


	// SEARCH

	$('#sideSearch form dt input, #searchTitle form dt input').focus( function () {
		$(this).removeClass('empty');
		$(this).addClass('focus');
		if($(this).val() == 'SEARCH') $(this).val('');
	}).blur( function () {
		$(this).removeClass('focus');
		if($(this).val() == '') $(this).val('SEARCH');
		if($(this).val() == '' || $(this).val() == 'SEARCH') $(this).addClass('empty');
	}).trigger('blur');
	$('#sideSearch form dd').css('top', Math.floor(($('#sideSearch form dt').height()-25)/2));


	// bottomBnr

	$('#bottomBnr a img').hover(
		function () {
			$(this).css('opacity', 0.7);
		},
		function () {
			$(this).css('opacity', 1);
		}
	);


	// indexList

	$('#indexList a img').hover(
		function () {
			$(this).css('opacity', 0.8);
		},
		function () {
			$(this).css('opacity', 1);
		}
	);


	// detailSide

	$('#detailSide a img').hover(
		function () {
			$(this).css('opacity', 0.8);
		},
		function () {
			$(this).css('opacity', 1);
		}
	);


	// seacthArea

	$('#seacthArea > div:last-child').addClass('last');
	$('#seacthArea a img').hover(
		function () {
			$(this).css('opacity', 0.8);
		},
		function () {
			$(this).css('opacity', 1);
		}
	);




	// fancybox
	$('a[rel]').fancybox({
		'titlePosition' : 'inside',
		'titleFormat' : function(titleStr, currentArray, currentIndex, currentOpts) {
			return $('[ <a href="' + currentOpts.href + '" target="_blank">印刷用画像を表示</a> ]');
		}
	});
});

function smoothScroll(hash) {
	var target = $(hash).offset().top;

	$(($.browser.safari) ? 'body' : 'html')
		.animate({scrollTop: target >= 15 ? target - 15 : target}, 600, 'swing', function(){$(this).unbind("mousewheel DOMMouseScroll");})
		.bind("mousewheel DOMMouseScroll",function(){
			$(this).queue([]).stop();
			$(this).unbind("mousewheel DOMMouseScroll");
		})
}


