var _Common_ = {
	initRollovers:function(){
		
		$('img[class=over]').hover(function(){
		
			$(this).attr("src",$(this).attr("src").replace("_off.","_on."));
		
		},function(){
			
			$(this).attr("src",$(this).attr("src").replace("_on.","_off."));
			
		});
		$('a[class=over]').hover(function(){
		
			$(this).find("img").each(function(){
				$(this).attr("src",$(this).attr("src").replace("_off.","_on."));
				$(this).attr("src",$(this).attr("src").replace("_off.","_on."));
			 })
		
		},function(){
			
			$(this).find("img").each(function(){
				$(this).attr("src",$(this).attr("src").replace("_on.","_off."));
			 })
			
		}).each(function(){
			var HREF = $(this).attr("href"); 
			$(this).find("img").click(function(){
				location.href = HREF;
			})
		});

		return false;
		
	},
	rand:function(x){
		number = Math.floor(Math.random() * x);
		return number;
	},
	url_Parse:function(url){
		var _ = false;
		if(url.indexOf("?") > 0 && url.indexOf("=") > 0){
			_ = new Array();
			var array = url.split("#");
			array = array[0].split("?");
			array = array[1].split("&");
			for(var i=0;i<array.length;i++){
				array[i] = array[i].split("=");
				var hash = array[i][0];
				var value = array[i][1];
				
				_[hash] = value;
			}
			delete array;
		}
		return _;
	},
	scrollInit:function(){
		$('a[href^=#]').click(function(){
			var href= this.hash;
			if(href == "") return false;
			var $target = $(href == '#TOP' ? 'body' : href);
			if($target.size()){ 
				var top = $target.offset().top; 
				$($.browser.safari ? 'body' : 'html')
				.animate({scrollTop:top}, 1000, 'easeOutCubic',function(){
				
					location.href = href;
//					location.replace(href);				
				}); 
				return false;
			}
		})
		$('area[href^=#]').click(function(){
			var href= this.hash;
			if(href == "") return false;
			var $target = $(href == '#TOP' ? 'body' : href);
			if($target.size()){ 
				var top = $target.offset().top; 
				$($.browser.safari ? 'body' : 'html')
				.animate({scrollTop:top}, 1000, 'easeOutCubic',function(){
				
					location.href = href;
//					location.replace(href);				
				}); 
				return false;
			}
		})
	
	},
	popupWindow:function(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)/3;
		var o = option+', width='+width+', height='+height+', left='+x+', top='+y;
		var win = window.open(url, windowName, o);
		
		if (win){
			win.focus();
			return false;
		} else {
			return true;
		}
	},
	menuCurrent:function(){
		
		
		
		var fileName = document.URL;
		fileName = fileName.replace(/\\/gi,"/");
		
		if(fileName.indexOf("/restaurant/") > 0){
		
			fileName = fileName.split("/");
			var path = fileName[fileName.length-2];
			fileName = fileName[fileName.length-1];
			fileName = fileName.split("#");
			
			
			$("#menu h2 a[href^=" + fileName + "]").each(function(){
		
				$(this).find("img").attr("src",$(this).find("img").attr("src").replace("_off.","_on.")).removeAttr("class");
				return false;
			});
			
			fileName = path + "/" +  fileName[0];
			$("#menu ul.main-menu li a[href$=" + fileName + "]").each(function(){
		
				$(this).find("img").attr("src",$(this).find("img").attr("src").replace("_off.","_on.")).removeAttr("class");
	
			});
			return false;
		}
		
		fileName = fileName.split("/");
		var path = fileName[fileName.length-2];
		fileName = fileName[fileName.length-1];
		fileName = fileName.split("#");
		fileName = fileName[0];
		
		
		
		$("#menu h2 a[href^=" + fileName + "]").each(function(){
	
			$(this).find("img").attr("src",$(this).find("img").attr("src").replace("_off.","_on.")).removeAttr("class");
			return false;
		});
		
		$("#menu ul.main-menu li a[href^=" + fileName + "]").each(function(){
	
			$(this).find("img").attr("src",$(this).find("img").attr("src").replace("_off.","_on.")).removeAttr("class");

		});

		
	}
};


var Cookie = { //cookie
	read:function(CookieName){
		if(document.cookie){
			var cookie_Data = document.cookie;
			var Name =cookie_Data.indexOf(CookieName + "=",0);
			if(Name >= 0){
				var Data = cookie_Data.indexOf(";",Name + CookieName.length + 1);
				Data >= 0? Data = cookie_Data.substring(Name + CookieName.length + 1,Data): Data = cookie_Data.substring(Name + CookieName.length + 1,cookie_Data.length);
				return(Data);
			}
		}
		return(false);
	},
	set:function(CookieName,Value){
		var time =new Date();
		time.setTime(time.getTime() + (1000*365*60*60*24));
		var exptime =";expires=" + time.toGMTString();
		document.cookie = CookieName + "=" + Value + exptime + "; path=/";
	},
	Delete:function(CookieName){
		var time =new Date();
		time.setTime(time.getTime() - (1000*365*60*60*24));
		var exptime =";expires=" + time.toGMTString();
		document.cookie = CookieName + "=" + exptime + "; path=/";
	}
};


var tab = {};
tab.init = function(){
	/*
	var i = 1;

	while($("#tab_" + i).length > 0){
		$("#tab_" + i).hide();
		i++;
	}
	*/
	
	$('img[class=tabImg]').each(function(i){
					
		
		if($(this).attr("src").indexOf("_on.") > 0){
			
			$(this).parent().attr("class","current");
			
		}else{
			$("#tab_" + i).hide();
			
		}
		
		$(this).hover(function(){
		
			$(this).attr("src",$(this).attr("src").replace("_off.","_on."));
		
		},function(){
			if($(this).parent().attr("class") != "current"){
			$(this).attr("src",$(this).attr("src").replace("_on.","_off."));
			}
			
		});
		
	});
	
};
tab.set = function(obj,num,ln){
	for(var i=0;i<ln;i++){
		$("#tab_" + i).hide();
	}
	
	$(obj).parent().parent().find("img").each(function(){
		
		$(this).attr("src",$(this).attr("src").replace("_on.","_off.")).parent().removeAttr("class");
		
	});
	$(obj).attr("class","current").find("img").attr("src",$(obj).find("img").attr("src").replace("_off.","_on."));

	$("#tab_" + (num-1)).show();
	
	return false;

};
tab.anchorLink = function(obj){
	var Href = $(obj).attr("href");
	Href = Href.split("#");
	Href = Href[1].split("_");
	Href = Href[1];

	tab.set($('img[class=tabImg]').eq(Href).parent(),2,3);

	return true;
	
};


var gallery = {};
gallery.current = 0;
gallery.init = function(){
	
	$(".gallery").hide().eq(0).show();
	
	$(".galleryList a").each(function(i){

		var num = i;
		$(this).click(function(){
			$(".gallery").stop().eq(gallery.current).css({opacity:1}).fadeOut(350,function(){
				$(".gallery").eq(num).fadeIn(350);
				gallery.current = num;
			})
			return false;
		});
	
	})
	
	
};

var index = {};
index.duration = 750;
index.easing = "easeOutCubic";
index.infoTimer = "";
index.timer = "";
index.current = 0;
index.init = function(){
	
	$(".indexInformation div > a").toggle(function(){
		//close method
		
		var aParam ={
			paddingTop:"19px",
			paddingBottom:"21px",
			paddingLeft:"21px"
		};
		$(this).stop().animate(aParam,index.duration,index.easing);
		var cssParam ={
			width:"380px",
			height:"50px"
		};
		$(".indexInformation").stop().animate(cssParam,index.duration,index.easing,function(){$(this).find("div > a").parent().attr("class","open")});
		clearTimeout(index.infoTimer);
	},
	function(){
		//open method 380*200
		
		var aParam ={
			paddingTop:"31px",
			paddingBottom:"24px",
			paddingLeft:"21px"
		};
		$(this).stop().animate(aParam,index.duration,index.easing).parent().attr("class","close");
		var cssParam ={
			width:"380px",
			height:"200px"
		};
		$(".indexInformation").stop().animate(cssParam,index.duration,index.easing);
		
	});
	
	index.infoTimer = setTimeout(function(){
		$(".indexInformation div > a").click();
	},5000);
	
	
	
	
	
	
	

	var ln = $(".top-main-block .mainImg ul:first li").length;
	$(".top-main-block .mainImg ul:first li").hide().eq(0).show();
	var src = "";
	src += '<ul class="pointer">';
	for(var i=0;i<ln;i++){
		if(i==0){
			src += '<li><a href="#" onclick="return index.img('+ i +',this);" class="current"><img src="img/top/mainimg_pointer.gif" alt="" /></a></li>';
		}else{
			src += '<li><a href="#" onclick="return index.img('+ i +',this);"><img src="img/top/mainimg_pointer.gif" alt="" /></a></li>';
		}
	}
	src += '</ul>';

	$(".top-main-block .mainImg").append(src);
	
	index.timer = setInterval(function(){
		var x = index.current +1;
		if(x >= $(".top-main-block .mainImg ul:first li").length){
		
			x = 0;
		}
		$(".top-main-block .mainImg .pointer li a").eq(x).click();
					
	},5000);
	
	$(".top-main-block .mainImg").mouseover(function(){
		clearInterval(index.timer);
	});
	$(".top-main-block .mainImg").mouseout(function(){
		index.timer = setInterval(function(){
			
		var x = index.current +1;
//		alert(x);
		if(x >= $(".top-main-block .mainImg ul:first li").length){
			x = 0;
		}
		$(".top-main-block .mainImg .pointer li a").eq(x).click();
						
		},5000);
	});
	
	
	
};
index.img = function(num,obj){
	
	$(obj).parent().parent().find("a").removeAttr("class");
	$(obj).attr("class","current");
	
	
	$(".top-main-block .mainImg ul:first li").eq(index.current).stop().css({opacity:1}).fadeOut(500);
	$(".top-main-block .mainImg ul:first li").eq(num).stop().fadeIn(500);
	index.current = num;
	
	return false;
	
};



jQuery(function($) {
	if($("#top-page-wrapper").length > 0){
		index.init();
	}
	if($(".galleryList").length > 0){
		gallery.init();
	}
	tab.init();
	
	with(_Common_){
		menuCurrent();
		initRollovers();
		scrollInit();
	}
	
	
	
	if(navigator.userAgent.indexOf("Android") < 0 && !WebKitDetect.isMobile() ){// for iPhone android
		fleXenv.globalInit();
	}else{
		$(".flexcroll").css({overflow:"scroll"})
		
	}

	try{
		//$("select").selectable();
		$("select[rel!=normal]").selectable();
		var calParam = {
			dayNamesMin:['日', '月', '火', '水', '木', '金', '土'],
			dateFormat: 'yy / mm / dd',
			monthNames: ['01','02','03','04','05','06','07','08','09','10','11','12'],
			showMonthAfterYear: true,
			yearSuffix: ' / '
		};
		$("#chkin").datepicker(calParam);
		$("#chkout").datepicker(calParam);

	}catch(e){
	}
	


	
});
jQuery.extend( jQuery.easing,
{
	def: 'easeOutCubic',
	easeOutCubic: function (x, t, b, c, d) {
		return c*((t=t/d-1)*t*t + 1) + b;
	}
});

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

