var intervalTimer;
var autoPointCount = 0;

$(document).ready(function() {
	$(".over").fadeTo(0, 0);
	$(".over").hover(
		function(){$(this).fadeTo(400, 1);return false;},
		function(){$(this).fadeTo(300, 0);return false;}
		);
});
function slideSwitch() {
	var $active = $('#slidephoto img.active');
	if ( $active.length == 0 ) $active = $('#slidephoto img:last');
	var $next =	$active.next().length ? $active.next() : $('#slidephoto img:first');
	$active.addClass('last-active');
	$next.css({opacity: 0.0})
	.addClass('active')
	.animate({opacity: 1.0}, 1000, function() {
				$active.removeClass('active last-active');
	});
}
$(function() {
		setInterval( "slideSwitch()", 4000 );
});

jQuery.event.add(window, "load", function(){
		 var fw = 220;				//fixed width
		 var fh = 100;				//fixed height
		 var sl = 'img.fiximg'; //selector
		 $(sl).each(function(){
				 var w = $(this).width();
				 var h = $(this).height();
				 if (w >= h) {
						 $(this).width(fw);
				 } else {
								$(this).height(fh);
				 }
		});
});


$(function($) {
	var noResetSpot = true;
	var noResetOnsen = true;
	var noResetArea = true;

// トップページのimagemap
	$("div#topbg div#tabmap ul.nav li.spot").click(function() {
		noResetSpot = true;
		if (intervalTimer) {
			clearInterval(intervalTimer);
		}
		autoPointCount = -1;
		setTabAutoStart();
		$("div#spot").css('background-position', '0 0');
	});
	$("div#topbg map#spotmap area").mouseover(function() {
		if (noResetSpot) {
			return false;
		}
/*
		if ($(this).attr('id') == 'mizuki') {
			$("div#spot").css('background-position', '0 -2160px');
		}
		else if ($(this).attr('id') == 'daisen') {
			$("div#spot").css('background-position', '0 -1620px');
		}
		else if ($(this).attr('id') == 'kamochi') {
			$("div#spot").css('background-position', '0 -1890px');
		}
		else if ($(this).attr('id') == 'shirakabe1' || $(this).attr('id') == 'shirakabe2') {
			$("div#spot").css('background-position', '0 -1080px');
		}
		else if ($(this).attr('id') == 'mitokusan1' || $(this).attr('id') == 'mitokusan2') {
			$("div#spot").css('background-position', '0 -1350px');
		}
		else if ($(this).attr('id') == 'chizu') {
			$("div#spot").css('background-position', '0 -810px');
		}
		else if ($(this).attr('id') == 'sakyu') {
			$("div#spot").css('background-position', '0 -270px');
		}
		else if ($(this).attr('id') == 'uradome1' || $(this).attr('id') == 'uradome2') {
			$("div#spot").css('background-position', '0 -540px');
		}
*/
	}).click(function() {
		if (intervalTimer) {
			clearInterval(intervalTimer);
		}
		if (noResetSpot) {
			if ($(this).attr('id') == 'mizuki') {
				$("div#spot").css('background-position', '0 -2160px');
			}
			else if ($(this).attr('id') == 'daisen') {
				$("div#spot").css('background-position', '0 -1620px');
			}
			else if ($(this).attr('id') == 'kamochi') {
				$("div#spot").css('background-position', '0 -1890px');
			}
			else if ($(this).attr('id') == 'shirakabe1' || $(this).attr('id') == 'shirakabe2') {
				$("div#spot").css('background-position', '0 -1080px');
			}
			else if ($(this).attr('id') == 'mitokusan1' || $(this).attr('id') == 'mitokusan2') {
				$("div#spot").css('background-position', '0 -1350px');
			}
			else if ($(this).attr('id') == 'chizu') {
				$("div#spot").css('background-position', '0 -810px');
			}
			else if ($(this).attr('id') == 'sakyu') {
				$("div#spot").css('background-position', '0 -270px');
			}
			else if ($(this).attr('id') == 'uradome1' || $(this).attr('id') == 'uradome2') {
				$("div#spot").css('background-position', '0 -540px');
			}
		}
		noResetSpot = true;
	}).mouseout(function() {
		if (noResetSpot) {
			return false;
		}
//		$("div#spot").css('background-position', '0 0');
	});

	$("div#topbg div#tabmap ul.nav li.yumeguri").click(function() {
		noResetOnsen = true;
		if (intervalTimer) {
			clearInterval(intervalTimer);
		}
		autoPointCount = 9;
		setTabAutoStart();
		$("div#yumeguri").css('background-position', '0 0');
	});
	$("div#topbg map#onsenmap area").mouseover(function() {
		if (noResetOnsen) {
			return false;
		}
/*
		if ($(this).attr('id') == 'kaike') {
			$("div#yumeguri").css('background-position', '0 -270px');
		}
		else if ($(this).attr('id') == 'hawai') {
			$("div#yumeguri").css('background-position', '0 -540px');
		}
		else if ($(this).attr('id') == 'sekigane') {
			$("div#yumeguri").css('background-position', '0 -810px');
		}
		else if ($(this).attr('id') == 'togo1' || $(this).attr('id') == 'togo2') {
			$("div#yumeguri").css('background-position', '0 -1350px');
		}
		else if ($(this).attr('id') == 'misasa') {
			$("div#yumeguri").css('background-position', '0 -1080px');
		}
		else if ($(this).attr('id') == 'hamamura') {
			$("div#yumeguri").css('background-position', '0 -1620px');
		}
		else if ($(this).attr('id') == 'shikano') {
			$("div#yumeguri").css('background-position', '0 -1890px');
		}
		else if ($(this).attr('id') == 'yoshioka') {
			$("div#yumeguri").css('background-position', '0 -2160px');
		}
		else if ($(this).attr('id') == 'tottori') {
			$("div#yumeguri").css('background-position', '0 -2430px');
		}
		else if ($(this).attr('id') == 'iwai') {
			$("div#yumeguri").css('background-position', '0 -2700px');
		}
		else if ($(this).attr('id') == 'goindex') {
			$("div#yumeguri").css('background-position', '0 -2970px');
		}
*/
	}).click(function() {
		if (intervalTimer) {
			clearInterval(intervalTimer);
		}
		if (noResetOnsen) {
			if ($(this).attr('id') == 'kaike') {
				$("div#yumeguri").css('background-position', '0 -270px');
			}
			else if ($(this).attr('id') == 'hawai') {
				$("div#yumeguri").css('background-position', '0 -540px');
			}
			else if ($(this).attr('id') == 'sekigane') {
				$("div#yumeguri").css('background-position', '0 -810px');
			}
			else if ($(this).attr('id') == 'togo1' || $(this).attr('id') == 'togo2') {
				$("div#yumeguri").css('background-position', '0 -1350px');
			}
			else if ($(this).attr('id') == 'misasa') {
				$("div#yumeguri").css('background-position', '0 -1080px');
			}
			else if ($(this).attr('id') == 'hamamura') {
				$("div#yumeguri").css('background-position', '0 -1620px');
			}
			else if ($(this).attr('id') == 'shikano') {
				$("div#yumeguri").css('background-position', '0 -1890px');
			}
			else if ($(this).attr('id') == 'yoshioka') {
				$("div#yumeguri").css('background-position', '0 -2160px');
			}
			else if ($(this).attr('id') == 'tottori') {
				$("div#yumeguri").css('background-position', '0 -2430px');
			}
			else if ($(this).attr('id') == 'iwai') {
				$("div#yumeguri").css('background-position', '0 -2700px');
			}
			else if ($(this).attr('id') == 'goindex') {
				$("div#yumeguri").css('background-position', '0 -2970px');
			}
		}
		noResetOnsen = true;
	}).mouseout(function() {
		if (noResetOnsen) {
			return false;
		}
//		$("div#yumeguri").css('background-position', '0 0');
	});

	$("div#topbg div#tabmap ul.nav li.area").click(function() {
		noResetArea = true;
		if (intervalTimer) {
			clearInterval(intervalTimer);
		}
		autoPointCount = 20;
		setTabAutoStart();
		$("div#area").css('background-position', '0 0');
	});
	$("div#topbg map#Map area").mouseover(function() {
		if (noResetArea) {
			return false;
		}
/*
		if ($(this).attr('id') == 'hino') {
			$("div#area").css('background-position', '0 -270px');
		}
		else if ($(this).attr('id') == 'yonago_sakaiminato') {
			$("div#area").css('background-position', '0 -540px');
		}
		else if ($(this).attr('id') == 'around_daisen') {
			$("div#area").css('background-position', '0 -810px');
		}
		else if ($(this).attr('id') == 'chubu') {
			$("div#area").css('background-position', '0 -1080px');
		}
		else if ($(this).attr('id') == 'tottori_iwami') {
			$("div#area").css('background-position', '0 -1350px');
		}
		else if ($(this).attr('id') == 'yazu') {
			$("div#area").css('background-position', '0 -1620px');
		}
*/
	}).click(function() {
		if (intervalTimer) {
			clearInterval(intervalTimer);
		}
		if (noResetArea) {
			if ($(this).attr('id') == 'hino') {
				$("div#area").css('background-position', '0 -270px');
			}
			else if ($(this).attr('id') == 'yonago_sakaiminato') {
				$("div#area").css('background-position', '0 -540px');
			}
			else if ($(this).attr('id') == 'around_daisen') {
				$("div#area").css('background-position', '0 -810px');
			}
			else if ($(this).attr('id') == 'chubu') {
				$("div#area").css('background-position', '0 -1080px');
			}
			else if ($(this).attr('id') == 'tottori_iwami') {
				$("div#area").css('background-position', '0 -1350px');
			}
			else if ($(this).attr('id') == 'yazu') {
				$("div#area").css('background-position', '0 -1620px');
			}
		}
		noResetArea = true;
	}).mouseout(function() {
		if (noResetArea) {
			return false;
		}
//		$("div#area").css('background-position', '0 0');
	});

// コンテンツフッターのimagemap

	$("div#footer map#spotmap area").mouseover(function() {
		if ($(this).attr('id') == 'mizuki') {
			$("div#spot").css('background-position', '0 -1776px');
		}
		else if ($(this).attr('id') == 'daisen') {
			$("div#spot").css('background-position', '0 -1332px');
		}
		else if ($(this).attr('id') == 'kamochi') {
			$("div#spot").css('background-position', '0 -1554px');
		}
		else if ($(this).attr('id') == 'shirakabe') {
			$("div#spot").css('background-position', '0 -1110px');
		}
		else if ($(this).attr('id') == 'mitokusan1' || $(this).attr('id') == 'mitokusan2') {
			$("div#spot").css('background-position', '0 -888px');
		}
		else if ($(this).attr('id') == 'chizu') {
			$("div#spot").css('background-position', '0 -666px');
		}
		else if ($(this).attr('id') == 'sakyu') {
			$("div#spot").css('background-position', '0 -444px');
		}
		else if ($(this).attr('id') == 'uradome') {
			$("div#spot").css('background-position', '0 -222px');
		}
	}).mouseout(function() {
			$("div#spot").css('background-position', '0 0');
	});

	$("div#footer map#onsenmap area").mouseover(function() {
		if ($(this).attr('id') == 'kaike') {
			$("div#yumeguri").css('background-position', '0 -2220px');
		}
		else if ($(this).attr('id') == 'hawai') {
			$("div#yumeguri").css('background-position', '0 -1998px');
		}
		else if ($(this).attr('id') == 'sekigane') {
			$("div#yumeguri").css('background-position', '0 -1776px');
		}
		else if ($(this).attr('id') == 'togo') {
			$("div#yumeguri").css('background-position', '0 -1332px');
		}
		else if ($(this).attr('id') == 'misasa') {
			$("div#yumeguri").css('background-position', '0 -1554px');
		}
		else if ($(this).attr('id') == 'hamamura') {
			$("div#yumeguri").css('background-position', '0 -1110px');
		}
		else if ($(this).attr('id') == 'shikano') {
			$("div#yumeguri").css('background-position', '0 -888px');
		}
		else if ($(this).attr('id') == 'yoshioka') {
			$("div#yumeguri").css('background-position', '0 -666px');
		}
		else if ($(this).attr('id') == 'tottori') {
			$("div#yumeguri").css('background-position', '0 -444px');
		}
		else if ($(this).attr('id') == 'iwai') {
			$("div#yumeguri").css('background-position', '0 -222px');
		}
		else if ($(this).attr('id') == 'goindex') {
			$("div#yumeguri").css('background-position', '0 -2442px');
		}
	}).mouseout(function() {
			$("div#yumeguri").css('background-position', '0 0');
	});

	$("div#footer map#areamap area").mouseover(function() {
		if ($(this).attr('id') == 'hino') {
			$("div#area").css('background-position', '0 -1110px');
		}
		else if ($(this).attr('id') == 'yonago_sakaiminato') {
			$("div#area").css('background-position', '0 -1332px');
		}
		else if ($(this).attr('id') == 'around_daisen') {
			$("div#area").css('background-position', '0 -888px');
		}
		else if ($(this).attr('id') == 'chubu') {
			$("div#area").css('background-position', '0 -666px');
		}
		else if ($(this).attr('id') == 'tottori_iwami') {
			$("div#area").css('background-position', '0 -222px');
		}
		else if ($(this).attr('id') == 'yazu') {
			$("div#area").css('background-position', '0 -444px');
		}
	}).mouseout(function() {
			$("div#area").css('background-position', '0 0');
	});

	$("div#searchBox div#areaBox div#miniAreamap map#catearea area").mouseover(function() {
		if ($(this).attr('id') == 'hino') {
			$("div#miniAreamap").css('background-position', '0 -1320px');
		}
		else if ($(this).attr('id') == 'yonagoSakaiminato') {
			$("div#miniAreamap").css('background-position', '0 -1100px');
		}
		else if ($(this).attr('id') == 'daisen') {
			$("div#miniAreamap").css('background-position', '0 -880px');
		}
		else if ($(this).attr('id') == 'chubu') {
			$("div#miniAreamap").css('background-position', '0 -660px');
		}
		else if ($(this).attr('id') == 'tottoriIwami') {
			$("div#miniAreamap").css('background-position', '0 -220px');
		}
		else if ($(this).attr('id') == 'yazu') {
			$("div#miniAreamap").css('background-position', '0 -440px');
		}
	}).mouseout(function() {
			$("div#miniAreamap").css('background-position', '0 0');
	});

	setTabAutoStart();

});

function tabDetail(id) {
	if (id == undefined) return false;
	if ($("div#" + id).size()) {
		$("div#" + id).parent().children('div').addClass('hide');
		$("div#" + id).removeClass('hide')
	}
}

function tabDetailChange(id) {
	if (id == undefined) return false;
	if ($("div#description div." + id).size()) {
		$("div#description div").addClass('hide');
	}
}

function runMovie(Src, Width, Height, Quality, Scale) {
	if (!Scale) {
		Scale = 'noscale';
	}

	document.write(
		"<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000'"
		+ " width='" + Width + "'"
		+ " height='" + Height + "'"
		+ " codebase='//download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0'>"
		+ "<param name='movie' value='" + Src + "'>"
		+ "<param name='quality' value='" + Quality + "'>"
		+ "<param name='menu' value='false'>"
		+ "<param name='wmode' value='transparent'>"
		+ "<embed src='" + Src + "'"
		+ " quality='" + Quality + "'"
		+ " width='" + Width + "'"
		+ " height='" + Height + "'"
		+ " scale='" + Scale + "'"
		+ " menu='false' wmode='transparent' pluginspage='//www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash'></embed></object>"
	);
}

function setTabAutoStart() {
	if (!document.getElementById('topbg')) {
		return false;
	}
	if (autoPointCount == 0) {
		$("div#spot").css('background-position', '0 -2160px');
		tabDetail('spot_mizuki');
		autoPointCount++;
	}
	intervalTimer = setInterval(function() {
		if (autoPointCount == 0) {
			$("div#spot").css('background-position', '0 -2160px');
			tabDetail('spot_mizuki');
		}
		else if (autoPointCount == 1) {
			$("div#spot").css('background-position', '0 -1890px');
			tabDetail('spot_kamochi');
		}
		else if (autoPointCount == 2) {
			$("div#spot").css('background-position', '0 -1620px');
			tabDetail('spot_daisen');
		}
		else if (autoPointCount == 3) {
			$("div#spot").css('background-position', '0 -1080px');
			tabDetail('spot_shirakabe');
		}
		else if (autoPointCount == 4) {
			$("div#spot").css('background-position', '0 -1350px');
			tabDetail('spot_mitokusan');
		}
		else if (autoPointCount == 5) {
			$("div#spot").css('background-position', '0 -810px');
			tabDetail('spot_chizu');
		}
		else if (autoPointCount == 6) {
			$("div#spot").css('background-position', '0 -270px');
			tabDetail('spot_sakyu');
		}
		else if (autoPointCount == 7) {
			$("div#spot").css('background-position', '0 -540px');
			tabDetail('spot_uradome');
		}
		else if (autoPointCount == 8) {
			$("div#topbg div#tabmap ul.nav li.yumeguri a").trigger('click');
		}
		else if (autoPointCount == 9) {
			$("div#yumeguri").css('background-position', '0 -270px');
			tabDetail('yumeguri_kaike');
		}
		else if (autoPointCount == 10) {
			$("div#yumeguri").css('background-position', '0 -810px');
			tabDetail('yumeguri_sekigane');
		}
		else if (autoPointCount == 11) {
			$("div#yumeguri").css('background-position', '0 -540px');
			tabDetail('yumeguri_hawai');
		}
		else if (autoPointCount == 12) {
			$("div#yumeguri").css('background-position', '0 -1080px');
			tabDetail('yumeguri_misasa');
		}
		else if (autoPointCount == 13) {
			$("div#yumeguri").css('background-position', '0 -1350px');
			tabDetail('yumeguri_togo');
		}
		else if (autoPointCount == 14) {
			$("div#yumeguri").css('background-position', '0 -1620px');
			tabDetail('yumeguri_hamamura');
		}
		else if (autoPointCount == 15) {
			$("div#yumeguri").css('background-position', '0 -1890px');
			tabDetail('yumeguri_shikano');
		}
		else if (autoPointCount == 16) {
			$("div#yumeguri").css('background-position', '0 -2160px');
			tabDetail('yumeguri_yoshioka');
		}
		else if (autoPointCount == 17) {
			$("div#yumeguri").css('background-position', '0 -2430px');
			tabDetail('yumeguri_tottori');
		}
		else if (autoPointCount == 18) {
			$("div#yumeguri").css('background-position', '0 -2700px');
			tabDetail('yumeguri_iwai');
		}
		else if (autoPointCount == 19) {
			$("div#topbg div#tabmap ul.nav li.area a").trigger('click');
		}
		else if (autoPointCount == 20) {
			$("div#area").css('background-position', '0 -540px');
			tabDetail('area_yonago');
		}
		else if (autoPointCount == 21) {
			$("div#area").css('background-position', '0 -270px');
			tabDetail('area_hino');
		}
		else if (autoPointCount == 22) {
			$("div#area").css('background-position', '0 -810px');
			tabDetail('area_daisen');
		}
		else if (autoPointCount == 23) {
			$("div#area").css('background-position', '0 -1080px');
			tabDetail('area_chubu');
		}
		else if (autoPointCount == 24) {
			$("div#area").css('background-position', '0 -1350px');
			tabDetail('area_tottori');
		}
		else if (autoPointCount == 25) {
			$("div#area").css('background-position', '0 -1620px');
			tabDetail('area_yazu');
		}
		else if (autoPointCount == 26) {
			$("div#topbg div#tabmap ul.nav li.spot a").trigger('click');
			autoPointCount = -1;
		}
		autoPointCount++;

	}, 5000);
}


