/*=====================================================
 - TOP MAIN VIDUAL
=====================================================*/
(function($) {
	var cache = [];
	$.preLoadImages = function() {
		var args_len = arguments.length;
		for (var i = args_len; i--;) {
			var cacheImage = document.createElement('img');
			cacheImage.src = arguments[i];
			cache.push(cacheImage);
   		 }
  	}
})(jQuery)
jQuery.preLoadImages(
	"common/img/top/mv1.jpg",
	"common/img/top/mv2.jpg",
	"common/img/top/mv3.jpg",
	"common/img/top/mv4.jpg",
	"common/img/top/mv5.jpg"
);




$(function(){
	var mvCnt = 5;
	var mvNum = 0;
	var mvAuto = setTimeout(mv_loop,7000);


	var mvImg = [
		"common/img/top/mv1.jpg",
		"common/img/top/mv2.jpg",
		"common/img/top/mv3.jpg",
		"common/img/top/mv4.jpg",
		"common/img/top/mv5.jpg"
	];
	
	$("#mv_switch li img").hide();
	$("#mv_switch li:first-child img").show();
	
	function mv_loop() {
		if (mvNum == mvCnt-1){
			mvNum=0;
		} else {
			mvNum+=1;
		};
		$("#mv_switch").css("background","url(common/img/top/mv"+(mvNum+1)+".jpg) left top no-repeat");
		$("#mvImg").fadeOut("100",
			function(){
				$("#mvImg").show().attr("src",mvImg[mvNum]);
			}
		);
		
		if(mvNum==0) {
			$("#mv_switch li img").hide();
			$("#mv_switch .sw_btn01 img").show();
		} else if(mvNum==1) {
			$("#mv_switch li img").hide();
			$("#mv_switch .sw_btn02 img").show();
		} else if(mvNum==2) {
			$("#mv_switch li img").hide();
			$("#mv_switch .sw_btn03 img").show();
		} else if(mvNum==3) {
			$("#mv_switch li img").hide();
			$("#mv_switch .sw_btn04 img").show();
		} else if(mvNum==4) {
			$("#mv_switch li img").hide();
			$("#mv_switch .sw_btn05 img").show();
		};
		mvAuto = setTimeout(mv_loop,7000);
	};
	
	
	$("#mv_switch li").hover(
		function(){
			if ($(this).index()==0) {
				$("#mv_switch").css("background","url("+(mvImg[0])+") left top no-repeat");
				$("#mvImg").hide().show().attr("src",mvImg[0]);
				$("#mv_switch .sw_btn02 img, #mv_switch .sw_btn03 img, #mv_switch .sw_btn04 img, #mv_switch .sw_btn05 img").hide();
				$("#mv_switch .sw_btn01 img").show();
			} else if ($(this).index()==1) {
				$("#mv_switch").css("background","url("+(mvImg[1])+") left top no-repeat");
				$("#mvImg").hide().show().attr("src",mvImg[1]);
				$("#mv_switch .sw_btn01 img, #mv_switch .sw_btn03 img, #mv_switch .sw_btn04 img, #mv_switch .sw_btn05 img").hide();
				$("#mv_switch .sw_btn02 img").show();
			} else if ($(this).index()==2) {
				$("#mv_switch").css("background","url("+(mvImg[2])+") left top no-repeat");
				$("#mvImg").hide().show().attr("src",mvImg[2]);
				$("#mv_switch .sw_btn01 img, #mv_switch .sw_btn02 img, #mv_switch .sw_btn04 img, #mv_switch .sw_btn05 img").hide();
				$("#mv_switch .sw_btn03 img").show();
			} else if ($(this).index()==3) {
				$("#mv_switch").css("background","url("+(mvImg[3])+") left top no-repeat");
				$("#mvImg").hide().show().attr("src",mvImg[3]);
				$("#mv_switch .sw_btn01 img, #mv_switch .sw_btn02 img, #mv_switch .sw_btn03 img, #mv_switch .sw_btn05 img").hide();
				$("#mv_switch .sw_btn04 img").show();
			} else if ($(this).index()==4) {
				$("#mv_switch").css("background","url("+(mvImg[4])+") left top no-repeat");
				$("#mvImg").hide().show().attr("src",mvImg[4]);
				$("#mv_switch .sw_btn01 img, #mv_switch .sw_btn02 img, #mv_switch .sw_btn03 img, #mv_switch .sw_btn04 img").hide();
				$("#mv_switch .sw_btn05 img").show();
			};

			this.style.cursor = "pointer";
			clearTimeout(mvAuto);

		},
		function(){
			mvAuto = setTimeout(mv_loop,1000);
		}
	);


});

//weather
$(function(){
	var tw = $(".weatherImg");
	
	if (tw.text()=="晴れ"){tw.css("background-image","url(/ski/common/img/top/img_weather_01.gif)")};
	if (tw.text()=="曇り"){tw.css("background-image","url(/ski/common/img/top/img_weather_02.gif)")};
	if (tw.text()=="雨"){tw.css("background-image","url(/ski/common/img/top/img_weather_03.gif)")};
	if (tw.text()=="雪"){tw.css("background-image","url(/ski/common/img/top/img_weather_04.gif)")};
	if (tw.text()=="晴れのち曇り"){tw.css("background-image","url(/ski/common/img/top/img_weather_0102.gif)")};
	if (tw.text()=="晴れのち雨"){tw.css("background-image","url(/ski/common/img/top/img_weather_0103.gif)")};
	if (tw.text()=="晴れのち雪"){tw.css("background-image","url(/ski/common/img/top/img_weather_0104.gif)")};
	if (tw.text()=="曇りのち晴れ"){tw.css("background-image","url(/ski/common/img/top/img_weather_0201.gif)")};
	if (tw.text()=="曇りのち雨"){tw.css("background-image","url(/ski/common/img/top/img_weather_0203.gif)")};
	if (tw.text()=="曇りのち雪"){tw.css("background-image","url(/ski/common/img/top/img_weather_0204.gif)")};
	if (tw.text()=="雨のち晴れ"){tw.css("background-image","url(/ski/common/img/top/img_weather_0301.gif)")};
	if (tw.text()=="雨のち曇り"){tw.css("background-image","url(/ski/common/img/top/img_weather_0302.gif)")};
	if (tw.text()=="雨のち雪"){tw.css("background-image","url(/ski/common/img/top/img_weather_0304.gif)")};
	if (tw.text()=="雪のち晴れ"){tw.css("background-image","url(/ski/common/img/top/img_weather_0401.gif)")};
	if (tw.text()=="雪のち曇り"){tw.css("background-image","url(/ski/common/img/top/img_weather_0402.gif)")};
	if (tw.text()=="雪のち雨"){tw.css("background-image","url(/ski/common/img/top/img_weather_0403.gif)")};
		
	//alert(tw.text())
});


//live camera
Count = 0;
function ImageRefresh() {
	document.CameraImage.src = "http://60.45.101.119/SnapshotJPEG?Resolution=320x240&Quality=Clarity&Count=" + Count;
	Count++;
}
$(function(){
	var hit = $(".camera dd");
	var img = $(".camera dd img");
	img.css({"opacity":"0","visibility":"hidden"});
	
	hit.hover(
		function(){
			img.css("visibility","visible");
			img.fadeTo("fast",1);
		},
		function(){
			img.fadeTo("fast",0),
			function(){img.css("visibility","hidden");};
		}
	);
});


//popup
function popupWindow(url, width, height, option, windowName){	
	if (!width) width = window.innerWidth || document.documentElement.clientWidth;
	if (!height) height = window.innerHeight || document.documentElement.clientHeight;
	if (!option) option = 'menubar=yes, toolbar=yes, location=yes, status=yes, scrollbars=yes, resizable=yes';
	if (!windowName) windowName = "popup";
	var x = (screen.availWidth - width)/2;
	var y = (screen.availHeight - height)/4;
	var o = option+', width='+width+', height='+height+', left='+x+', top='+y;
	var blockMessage = "ウィンドウがお使いのブラウザでポップアップブロックされました。\nポップアップブロックを解除してください。";
	var win = window.open(url, windowName, o);
	if (win){
		win.focus();
	} else {
		alert(blockMessage);
	}
}
