// JavaScript Document

// Lightpop
(function($){
	$(function(){
		if (!$("a.lightpop").length || $.lightpop) return;
		$("a.lightpop").lightpop();
	});
})(jQuery);

(function($){
	$.extend($.support, {
		orientation		: ("orientation" in window),
		touch			: ("ontouchend" in document && "ontouchstart" in document)
	});
	$(function(){
		if (!$.support.touch) { return; }
		if ((/iPhone|iPod/i).test(navigator.userAgent)) {
			setTimeout(function(){ if (window.pageYOffset === 0) { window.scrollTo(0,1); } }, 100);
			
			$(window).bind("orientationchange",function(event){
				//window.orientation 0 90 180 -90
				event.preventDefault();
				setTimeout(function(){ if (Math.round(window.pageYOffset / 10) <= 10) { window.scrollTo(0,1); } }, 100);
			});
		}
	});
})(jQuery);


// 予約フォーム
(function($){
	$(function(){
		if (!$("form#frmplanseek").length) return;
		var now	= new Date();
		// Year
		$("select[name=cmbARRY]").val(now.getFullYear());
		// Month
		$("select[name=cmbARRM]").val(now.getMonth() + 1);
		// Date
		$("select[name=cmbARRD]").val(now.getDate());
		
		$("form#frmplanseek").submit(function(){ return false; });
		$("form#frmplanseek :input[name=submit]").click(function(){
			var hcod1	= "61550";
			var hcod2	= "001";
			
			$(":input[name=hidSELECTARRYMD]").val($("select[name=cmbARRY]").val() + "/" + $("select[name=cmbARRM]").val() + "/" + $("select[name=cmbARRD]").val());
			var url		= 'https://asp.hotel-story.ne.jp/ver3d/planlist.asp?hcod1=' + hcod1 + '&hcod2=' + hcod2 + '&hidmode=select&mode=seek&hidSELECTARRYMD='+ $(":input[name=hidSELECTARRYMD]").val() + '&hidSELECTHAKSU='+ $(":input[name=hidSELECTHAKSU]").val() + '&hidSELECTadult='+ $(":input[name=cmbADULT]").val();
			
			window.location.href	= url;
			/*var subwin = window.open(url, 'planlist', 'width=920,Height=650,resizable=yes,scrollbars=yes,status=yes');
			subwin.focus();*/
			
			return false;
		});
		
	});
	$(function(){
		$(".reservation a, a.reservation").click(function(){
			var href	= $(this).attr("href");
			if ((/^#|javascript\:/).test(href)) return false;
			var subwin = window.open(href, "popUpWin", "width=900,height=650,resizable=yes,scrollbars=yes,status=yes");
			subwin.focus();
			return false;
		});
		$(".popup a, a.popup").click(function(){
			var href	= $(this).attr("href");
			if ((/^#|javascript\:/).test(href)) return false;
			var subwin = window.open(href, "popUpSubWin", "width=760,height=400,resizable=yes,scrollbars=yes,status=yes");
			subwin.focus();
			return false;
		});
	});
})(jQuery);


// プロデュース
(function($){
	$(function(){
		if (!$("#main").hasClass("produce")) return;
		if (!$("#mnav ul").length) {
			setInterval(function(){
				var img		= $("#produce img.selected");
				var src		= img.attr("src");
				if (!src) return;
				$("#produce").css({"backgroundImage":"url(" + src + ")"});
				$("#produce img").css({"display":"none"}).removeClass("selected");
				var next	= img.next();
				if (!next.length) { next = $("#produce img:first"); }
				next.addClass("selected").fadeIn(1000);
			}, 5000);
		} else {
			$("#produce").bind("cheage", function(){
				
				var self	= $("#mnav ul li a.selected");
				var ul		= self.parent().parent();
				
				var src		= $("#produce img.selected").attr("src");
				if (!src) return;
				$("#produce").css({"backgroundImage":"url(" + src + ")"});
				$("#produce img").css({"display":"none"}).removeClass("selected");
				
				$("#produce ul li").css({"display":"none"}).removeClass("selected");
				
				$("a", ul).each(function(index, elem){
					$(elem).removeClass("selected");
					if (self.get(0) == $(elem).get(0)) {
						self.addClass("selected");
						$("#produce ul li:eq(" + index + ")").css({"display":"block"}).addClass("selected");
						$("#produce img:eq(" + index + ")").addClass("selected").fadeIn();
					}
				});
			});
			
			
			$("#mnav ul li a").hover(function(e){
				$("#mnav ul li a").removeClass("selected");
				$(this).addClass("selected");
				$("#produce").trigger("cheage");
			},function(){});
		}
	});
})(jQuery);
