﻿// rollover 標準的なロールオーバー
function initRollOverImages() {
	var image_cache = new Object();
	$("img.swap, input.swap").each(function(i) {
		var imgsrc = this.src;
		var dot = this.src.lastIndexOf('.');
		var imgsrc_ov = this.src.substr(0, dot) + '_ov' + this.src.substr(dot, 4);
		image_cache[this.src] = new Image();
		image_cache[this.src].src = imgsrc_ov;
		$(this).hover(function() { this.src = imgsrc_ov; },function() { this.src = imgsrc; });
	});
};





// footerbtn rollover フッター実績リストのロールオーバー
function initFooterbtnRollOverImages() {
	$("ul.ftrResults a img").mouseover(function(){
		if ($(this).attr("src").match(/ftr_btn/)) {
	   	$(this).stop().fadeTo("fast", 0.5);
	   }else return;
	});
	
	$("ul.ftrResults a img").mouseout(function(){
		if ($(this).attr("src").match(/ftr_btn/)) {
	   	$(this).stop().fadeTo("fast", 1);
	   }else return;
	});
};





// scrollTop ページ上部までスクロール
function gotoTop() {
	$(".bkToPagetop a").click(function(){
		$('html, body').animate({ scrollTop: $($(this).attr("href")).offset().top }, 'fast','swing');
		return false;
	});
};





// year　コピーライトの年取得
function thisYear() {
	var day = new Date();
	var year = day.getFullYear();
	$('span.year').text(year);
};





// popUpWindows　標準的なポップアップウィンドウ表示（onclick使う方法です）
function windowPop(URL,windowName,features) {
	window.open(URL,windowName,features);
	return false;
};





// print window
function printThis() {
	this.print();
};





// contentsNav now　サイドナビゲーションのカレント表示
function contentsNav() {
	$("nav.contentsNav ul").each(function() {
		var where = $("body").attr('id');
		var here = "is_" + where;

		$("li", this).each(function(index){
		var $this = $(this);
		var hereIs = $(this).attr('id');
		if(hereIs === here) $this.addClass("now");
		});
	});
};





// equalHeight　指定したブロックの高さを揃える
function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = $(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	group.height(tallest);
};





// ページ読込時に実行です
$(document).ready(function() {

	// allList load
	$('div#allList #allListArticles').load('/results/resultlist.html', function(){
		// !bookmark スクロールバー実装 ロード後のコールバックの為にalllist.jsから移動
		$("div#allList .scrollHandle").html('<div class="scrollHandleLine"></div>');
		var scrollBarHeight = 320 * (360 / $("#allList ul").height());
		$("div#allList .scrollHandle").css({height: scrollBarHeight});
		$("div#allList .scrollHandle").draggable({
			drag:function(e,ui){
				var parcent=$(this).css("top").replace("px","")/320;
				$("#allList ul#allListArticles").css({marginTop: -$("#allList ul#allListArticles").height()*parcent});
			},
			containment:"parent",
			axis:"y"
		});
	});


	// footer results load
	$('div#ftrCarousel ul.ftrResults').load('/results/resultlist_ftr.html', function(){
		// jCarousel footer
		$('.ftrResults').jcarousel({
			//size: mycarousel_itemList.length,
			//itemLoadCallback: {onBeforeAnimation: mycarousel_itemLoadCallback},
			auto: 5,
			scroll: 3,
			animation: 'slow',
			wrap: 'circular'
		});
		// footer rollover
		initFooterbtnRollOverImages();
	});

	// rollover
	initRollOverImages();

	// contentsNav
	contentsNav();

	// equalHeight
	equalHeight($("div.resultsBlock li"));
	equalHeight($("div.smListBlock"));

	// gotoTop
	gotoTop();

	// year
	thisYear();

});


