
/* --------------------------------
	ロールオーバー
-------------------------------- */

$(function() {
	rollover('.rollover', '_ov');
});

function rollover(target, hover, active, focus) {
	$(target).each(function() {
		var isActive = active && new RegExp(active + '(\.gif|\.jpg|\.png)([\?].*|$)').test(this.src);
		if (isActive && !focus) return;
		this.src.match('(\.gif|\.jpg|\.png)([\?].*|$)');
		var ext = RegExp.$1;
		var search = (isActive && focus) ? active + ext : ext;
		var replace = (isActive && focus) ? focus + ext : hover + ext;
		var out = this.src;
		var over = this.src.replace(search, replace);

		// プレロード
		new Image().src = over;

		// イベントの追加
		$(this).bind('mouseout', function() {
			this.src = out;
		}).bind('mouseover', function() {
			this.src = over;
		});
	});
}





/* --------------------------------
	GALLERY
-------------------------------- */

// setサムネイル
function setThumbnail(){
	document.write('<div id="thumbnail">');
	document.write('<ul>');
	for (i = 1; i <= gN; i++) {
		document.write('<li><a href="javascript:call(' + i + ');" onmouseover="thumbnailOver(' + i + ');" onmouseout="thumbnailOut(' + i + ');"><img src="img/thumbnail_' + i + '.jpg" alt="" width="40" height="40" id="thumbnailImg' + i + '" /></a></li>');
	}
	document.getElementById('thumbnailImg1').src = 'img/thumbnail_' + 1 + '_ov.jpg';
	document.write('</ul>');
	document.write('</div>');
}


// set矢印
function setArrow(){
	if (gN != 1) {
		var firstArrow = 1 + 1;
		document.write('<div id="arrow1"><ul><li class="next"><a href="javascript:call(' + firstArrow + ');"><img src="../../../common/photo_gallery/next.gif" alt="→" width="27" height="27" class="rollover" /></a></li></ul></div>');
		
		var lastArrow = gN - 1;
		document.write('<div class="arrowNone" id="arrow' + gN + '"><ul><li class="back"><a href="javascript:call(' + lastArrow + ');"><img src="../../../common/photo_gallery/back.gif" alt="←" width="27" height="27" class="rollover" /></a></li></ul></div>');
		
		for (i = 2; i < gN; i++) {
			var nextArrow = i + 1;
			var backArrow = i - 1;
			document.write('<div class="arrowNone" id="arrow' + i + '"><ul><li class="next"><a href="javascript:call(' + nextArrow + ');"><img src="../../../common/photo_gallery/next.gif" alt="→" width="27" height="27" class="rollover" /></a></li><li class="back"><a href="javascript:call(' + backArrow + ');"><img src="../../../common/photo_gallery/back.gif" alt="←" width="27" height="27" class="rollover" /></a></li></ul></div>');
		}
	}
}


// 画像切り替え
var cN = 1;

function switchImg(now){
	document.getElementById('image').src = 'img/img_' + now + '.jpg';
	cN = now;
}



// サムネイルロールオーバー
function thumbnailOver(now) {
	for (i = 1; i <= gN; i++) {

		if (i == now){
			document.getElementById('thumbnailImg' + now).src = 'img/thumbnail_' + now + '_ov.jpg';
		}
		if (i != now && i != cN){
			document.getElementById('thumbnailImg' + i).src = 'img/thumbnail_' + i + '.jpg';
		}
	}
}

function thumbnailOut(now){
	for (i = 1; i <= gN; i++) {
		if (i != cN){
			document.getElementById('thumbnailImg' + i).src = 'img/thumbnail_' + i + '.jpg';
		}
	}
}



// サムネイルcurrent
function thumbnailCurrent(now){
	for (i = 1; i <= gN; i++) {
		if (i == now){
			document.getElementById('thumbnailImg' + now).src = 'img/thumbnail_' + now + '_ov.jpg';
		}
		else {
			document.getElementById('thumbnailImg' + i).src = 'img/thumbnail_' + i + '.jpg';
		}
	}	
}



// 矢印切り替え
function switchArrow(now){
	
	for (i = 1; i <= gN; i++){
		if (i == now) {
			if(document.getElementById('arrow' + i)){
				document.getElementById('arrow' + i).style.display = 'block';
			}
		}
		else {
			if(document.getElementById('arrow' + i)){;
				document.getElementById('arrow' + i).style.display = 'none';
			}
		}
	}
}


// 呼び出し
function call(now){
	thumbnailCurrent(now);
	switchArrow(now);
	switchImg(now);
}



